Documentation Index
Fetch the complete documentation index at: https://mintlify.com/EdgarJr30/proyecto-de-grado-cms/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Thesend-push-from-outbox Edge Function is a Deno-based worker that processes the notification_outbox table and delivers Web Push notifications to subscribed browsers.
Location:
supabase/functions/send-push-from-outbox/index.tsArchitecture
The Edge Function implements a claim-and-process pattern for concurrency-safe delivery:Claim Pending Rows
Uses
claim_notification_outbox_batch RPC with SKIP LOCKED to atomically claim rows without conflictsSend Push Payload
Uses
web-push library to send notifications to all endpoints with VAPID authenticationEnvironment Variables
Required Secrets
Set these vianpx supabase secrets set:
| Variable | Description | Example |
|---|---|---|
SUPABASE_URL | Your Supabase project URL | https://abc123.supabase.co |
SUPABASE_SERVICE_ROLE_KEY | Service role key (never anon key) | eyJhbGc... |
VAPID_PUBLIC_KEY | VAPID public key from generation step | BKxW8z... |
VAPID_PRIVATE_KEY | VAPID private key (keep secret) | y3dK... |
Optional Configuration
| Variable | Description | Default |
|---|---|---|
VAPID_SUBJECT | Contact email or URL | mailto:notifications@example.com |
PUSH_OUTBOX_CRON_SECRET | Shared secret for webhook authentication | (none) |
PUSH_OUTBOX_MAX_ATTEMPTS | Max retries before marking as error | 8 |
PUSH_OUTBOX_BACKOFF_BASE_SECONDS | Initial retry delay | 15 |
PUSH_OUTBOX_BACKOFF_MAX_SECONDS | Maximum retry delay | 900 (15 min) |
PUSH_OUTBOX_PROCESSING_LEASE_SECONDS | How long to hold a processing lock | 120 (2 min) |
PUSH_OUTBOX_MAX_PARALLEL_SENDS | Concurrent push sends per batch | 8 |
Deployment
Step 1: Set Secrets
Step 2: Deploy Function
Step 3: Verify Deployment
Test with a manual invocation:Invocation Modes
Mode 1: Batch Processing
Process multiple pending rows (default):- Claims up to
limitpending rows (default 100, max 250) - Processes in parallel with
MAX_PARALLEL_SENDSworkers - Returns aggregate stats
Mode 2: Single Row
Process a specific outbox row by ID:- Useful for webhook-triggered immediate delivery
- Bypasses normal queue ordering
Retry Logic
The function implements exponential backoff with configurable bounds:| Attempt | Delay |
|---|---|
| 1 | 15s |
| 2 | 30s |
| 3 | 1m |
| 4 | 2m |
| 5 | 4m |
| 6 | 8m |
| 7+ | 15m (capped) |
MAX_ATTEMPTS (default 8), rows are marked as error and stop retrying.
Subscription Cleanup
The function automatically removes expired subscriptions:- 410 Gone: User unsubscribed
- 404 Not Found: Subscription no longer valid
Webhook Configuration
Option A: Database Trigger (pg_net)
Recommended for immediate delivery without external dependencies.
ALTER DATABASE privilege):
trg_enqueue_push_outbox_dispatch trigger (line 1421 in 16_notifications.sql) will invoke the function via pg_net.http_post immediately when rows are inserted.
Option B: Database Webhook
Create a webhook in Supabase Dashboard:- Navigate to Database → Webhooks → Create a new hook
- Configure:
- Table:
public.notification_outbox - Events:
INSERT - Type:
HTTP Request - Method:
POST - URL:
https://<project-ref>.functions.supabase.co/send-push-from-outbox?limit=1
- Table:
- Add headers:
Option C: Cron Fallback
Always recommended as a safety net, even with immediate triggers.
Monitoring
Check Outbox Health
Function Logs
View Edge Function logs in Supabase Dashboard:- Navigate to Edge Functions →
send-push-from-outbox - Click Logs tab
- Filter by
status >= 400for errors
Unauthorized: Missing or invalidx-cron-secretInvalid outbox_id format: Malformed UUID in query parampush_send_failed: All subscriptions failed (check endpoint validity)
Performance Tuning
Adjust Parallelism
Increase for high-volume deployments:Batch Size
Increase the cronlimit parameter for larger batches:
Processing Lease
Reduce if workers are terminating prematurely:Troubleshooting
No Notifications Sent
-
Check outbox has pending rows:
-
Verify function secrets are set:
- Test manual invocation (see Verify Deployment above)
-
Check user has active subscription:
Rows Stuck in Processing
If rows remain inprocessing status:
-
Check if processing lease expired:
- The next cron/claim call will automatically retry expired leases
-
Or manually reset:
High Error Rate
-
Check subscription validity:
-
Review error messages:
-
Common causes:
- Expired VAPID keys (regenerate and redeploy)
- User revoked notification permission
- Browser/OS blocking push
Next Steps
Configure PWA
Set up service worker registration and subscription management in the frontend