Skip to content

Commit 3c9ad86

Browse files
committed
docs: clarify worker safety net setup and update scheduling commands
- Improved description of setting up a pg_cron safety net for worker management - Added instructions to customize worker name and API key placeholders - Corrected cron unschedule command to match the safety net job name - Updated wording for clarity and consistency in the documentation
1 parent fff104b commit 3c9ad86

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

‎pkgs/website/src/content/docs/how-to/keep-workers-up.mdx‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ sidebar:
77

88
import { Aside, Steps } from "@astrojs/starlight/components";
99

10-
Set up a pg_cron safety net that checks worker status and only starts new workers when needed, preventing cost overruns from uncontrolled spawning.
10+
Set up a pg_cron safety net that checks worker status and only starts new workers when needed, making workers spawning more predictable.
1111

1212
<Aside type="caution" title="Prerequisites">
1313
- Deployed Edge Worker function on Supabase.com
@@ -26,18 +26,21 @@ This approach checks existing worker counts before spawning new ones:
2626
<Steps>
2727

2828
1. **Create the safety net cron job**
29+
30+
Remember to change `<your-worker-name>` to name of your worker's Edge Function and `<YOUR_ANON_KEY>` to match your project's ANON key.
31+
2932
```sql
3033
SELECT cron.schedule(
31-
'worker-safety-net',
34+
'watchdog--<your-worker-name>',
3235
'10 seconds',
3336
$$
3437
SELECT net.http_post(
35-
url := 'https://your-project.supabase.co/functions/v1/your-worker-name',
36-
headers := jsonb_build_object('Authorization', 'Bearer YOUR_ANON_KEY')
38+
url := 'https://your-project.supabase.co/functions/v1/<your-worker-name>',
39+
headers := jsonb_build_object('Authorization', 'Bearer <YOUR_ANON_KEY>')
3740
) AS request_id
3841
WHERE (
3942
SELECT COUNT(DISTINCT worker_id) FROM pgflow.workers
40-
WHERE function_name = 'your-worker-name'
43+
WHERE function_name = 'your-worker-name'
4144
AND last_heartbeat_at > NOW() - INTERVAL '2 min'
4245
) < 2;
4346
$$
@@ -63,9 +66,5 @@ More frequent checks mean faster worker recovery but consume more HTTP requests
6366

6467
To disable the safety net:
6568
```sql
66-
SELECT cron.unschedule('worker-safety-net');
69+
SELECT cron.unschedule('watchdog--<worker-safety-net>');
6770
```
68-
69-
<Aside type="tip" title="Cost Control">
70-
This approach provides predictable costs since you control exactly how many workers run, unlike basic safety nets that can spawn unlimited instances.
71-
</Aside>

0 commit comments

Comments
 (0)