forked from supabase/smart-office-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_cron_manually.sql
More file actions
52 lines (46 loc) · 1.56 KB
/
setup_cron_manually.sql
File metadata and controls
52 lines (46 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
-- Manual setup for pg_net and cron jobs
-- Run this in your Supabase SQL Editor
-- Step 1: Enable extensions
CREATE EXTENSION IF NOT EXISTS pg_cron;
CREATE EXTENSION IF NOT EXISTS pg_net;
-- Step 2: Grant permissions
GRANT USAGE ON SCHEMA cron TO postgres;
GRANT USAGE ON SCHEMA net TO postgres;
-- Step 3: Schedule capacity violation detector (every 3 minutes)
SELECT cron.schedule(
'capacity-violation-detector',
'*/3 * * * *', -- Every 3 minutes
$$
SELECT net.http_post(
url := 'https://nnipoczsqoylnrwidbgp.supabase.co/functions/v1/capacity-violation-detector',
headers := '{"Authorization": "Bearer YOUR_ANON_KEY", "Content-Type": "application/json"}'::jsonb,
body := '{}'::jsonb
);
$$
);
-- Step 4: Schedule sensor data simulator (every minute)
SELECT cron.schedule(
'sensor-data-simulator',
'* * * * *', -- Every minute
$$
SELECT net.http_post(
url := 'https://nnipoczsqoylnrwidbgp.supabase.co/functions/v1/sensor-data-simulator',
headers := '{"Authorization": "Bearer YOUR_ANON_KEY", "Content-Type": "application/json"}'::jsonb,
body := '{}'::jsonb
);
$$
);
-- Step 5: Schedule room booking simulator (every 90 minutes)
SELECT cron.schedule(
'room-booking-simulator',
'*/90 * * * *', -- Every 90 minutes
$$
SELECT net.http_post(
url := 'https://nnipoczsqoylnrwidbgp.supabase.co/functions/v1/room-booking-simulator',
headers := '{"Authorization": "Bearer YOUR_ANON_KEY", "Content-Type": "application/json"}'::jsonb,
body := '{}'::jsonb
);
$$
);
-- Step 6: Verify the cron jobs are scheduled
SELECT * FROM cron.job;