Cronjobs dont run

For some reason cronjobs dont run. It says next job will be next minute but that minute passes but nothing runs. No record of a job not even with failed status. When i click the 3 dots and run job manually then it does run.
No description
3 Replies
Idris
IdrisOP5d ago
CREATE OR REPLACE FUNCTION private.trigger_notification_processing()
RETURNS void
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = ''
AS $$
DECLARE
service_key TEXT;
base_url TEXT;
BEGIN
-- Check if there is any work to do before proceeding.
IF EXISTS (SELECT 1 FROM public.notifications WHERE status = 'pending' LIMIT 1) THEN

service_key := private.get_secret('supabase_service_role_key');
base_url := private.get_setting('SUPABASE_URL');

-- Call the webhook to process notifications.
PERFORM net.http_post(
url := base_url || '/functions/v1/process-pending-notifications',
headers := jsonb_build_object(
'Content-Type', 'application/json',
'Authorization', 'Bearer ' || service_key
),
body := '{}'::jsonb,
-- Set a timeout to prevent the cron job from hanging.
timeout_milliseconds := 2000
);
END IF;
END;
$$;

SELECT cron.schedule(
'process-notifications',
'* * * * *', -- The cron schedule: run at the start of every minute
'SELECT private.trigger_notification_processing()'
);
CREATE OR REPLACE FUNCTION private.trigger_notification_processing()
RETURNS void
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = ''
AS $$
DECLARE
service_key TEXT;
base_url TEXT;
BEGIN
-- Check if there is any work to do before proceeding.
IF EXISTS (SELECT 1 FROM public.notifications WHERE status = 'pending' LIMIT 1) THEN

service_key := private.get_secret('supabase_service_role_key');
base_url := private.get_setting('SUPABASE_URL');

-- Call the webhook to process notifications.
PERFORM net.http_post(
url := base_url || '/functions/v1/process-pending-notifications',
headers := jsonb_build_object(
'Content-Type', 'application/json',
'Authorization', 'Bearer ' || service_key
),
body := '{}'::jsonb,
-- Set a timeout to prevent the cron job from hanging.
timeout_milliseconds := 2000
);
END IF;
END;
$$;

SELECT cron.schedule(
'process-notifications',
'* * * * *', -- The cron schedule: run at the start of every minute
'SELECT private.trigger_notification_processing()'
);
garyaustin
garyaustin5d ago
Supabase Docs | Troubleshooting | pg_cron debugging guide
Supabase is the Postgres development platform providing all the backend features you need to build a product.
Idris
IdrisOP5d ago
Ah that helped, thanks!

Did you find this page helpful?