Integrate
Background Jobs
Setting up background async processes, i.e email notifications for new user signups using Supabase queue and cron with a Sveltekit endpoint
Enable the Supabase Integrations
- Go to your Supabase project dashboard
- Navigate to Database -> Extensions
- Enable the
pg_cron
extension (required to schedule jobs) - Enable the
pg_net
extension (required for making HTTP requests) - Enable the
pg_queue
extension (required for background message processing)
Configure Queue Settings
- Go to Queue Settings in your Supabase dashboard
- Enable "Expose Queues via PostgREST" to allow interaction with queues using the Supabase client SDK
- Navigate to the Queue Dashboard
- Click "Create a Queue" and provide a name (e.g., "email_signups")
- Select "Basic" for the queue type
- Click "Create Queue"
Modify Existing User Handler Function
In the SQL Editor update your existing user handler function to include queueing:
Create API Endpoint
Create a new API endpoint to process the queue:
Setup Cron Job for Queue Processing
Create a cron job and execute it to call your API endpoint every 5 minutes:
Environment Variables
Ensure you updated these variables in your
.env
file:
TIP
You can view any unprocessed queue messages in the Supabase dashboard under Integrations -> Queues.