File size: 1,299 Bytes
9b81983
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
-- Vion Training — scheduled email jobs (run in the Supabase SQL Editor).
-- Uses pg_cron (scheduler) + pg_net (outbound HTTP) to call the deployed
-- backend's /cron endpoints on a timer. Both extensions are available on the
-- Supabase free tier.

create extension if not exists pg_cron;
create extension if not exists pg_net;

-- Weekly summary / encouragement — every Monday at 07:00 UTC.
select cron.schedule(
  'vion-weekly',
  '0 7 * * 1',
  $$
  select net.http_post(
    url := 'https://monicacarter-vion-training-v2.hf.space/cron/weekly',
    headers := jsonb_build_object(
      'Content-Type', 'application/json',
      'X-Cron-Secret', 'uIfqNB0nq5njAgFWdYLK6lzIR_YcX_j7zDhAD--XCqA'
    ),
    body := '{}'::jsonb
  );
  $$
);

-- 5-hour-before reminders — every 15 minutes.
select cron.schedule(
  'vion-reminders',
  '*/15 * * * *',
  $$
  select net.http_post(
    url := 'https://monicacarter-vion-training-v2.hf.space/cron/reminders',
    headers := jsonb_build_object(
      'Content-Type', 'application/json',
      'X-Cron-Secret', 'uIfqNB0nq5njAgFWdYLK6lzIR_YcX_j7zDhAD--XCqA'
    ),
    body := '{}'::jsonb
  );
  $$
);

-- To inspect / remove later:
--   select * from cron.job;
--   select cron.unschedule('vion-weekly');
--   select cron.unschedule('vion-reminders');