S
Supabase3mo ago
Catto

CRON SCHEDULER DOESNT WORK!?

aaaaaaaaaaaaaaa
71 Replies
Catto
CattoOP3mo ago
select cron.schedule(
'call-every-1-minute-boy',
'*/1 * * * *',
$$
insert into payment_capture_logs (status_code, message)
select
status as status_code,
case
when status = 200 then content::json->>'message'
else content::text
end as message
FROM http((
'POST',
'https://fsahgwRHERWhj.ngrok-free.app/api/Stripe/capture-payments',
ARRAY[
http_header('Authorization', 'Bearer ..I-'),
http_header('Content-Type', 'application/json'),
http_header('X-Cron-Secret', 'u')
]::http_header[],
'application/json',
'{}'
));
$$
);
select cron.schedule(
'call-every-1-minute-boy',
'*/1 * * * *',
$$
insert into payment_capture_logs (status_code, message)
select
status as status_code,
case
when status = 200 then content::json->>'message'
else content::text
end as message
FROM http((
'POST',
'https://fsahgwRHERWhj.ngrok-free.app/api/Stripe/capture-payments',
ARRAY[
http_header('Authorization', 'Bearer ..I-'),
http_header('Content-Type', 'application/json'),
http_header('X-Cron-Secret', 'u')
]::http_header[],
'application/json',
'{}'
));
$$
);
this cron scheduler DOESNT WANNA WORK I SCHEDULE IT RIGHT, IT SAYS CRON IS CHEDULED AND ACTIVE but my endpoint is never being hit!?
Catto
CattoOP3mo ago
No description
Catto
CattoOP3mo ago
well it was hit once, when i tested manually calling that ngrok to see if it would hit my endpoint and IT =DID so why is that cron scheduler not working as it should?
garyaustin
garyaustin3mo ago
Are you getting Postgres errors in the log? If you look in this table do you see the cron running?
No description
garyaustin
garyaustin3mo ago
Most likely it is your POST call not working.
Catto
CattoOP3mo ago
No description
Catto
CattoOP3mo ago
the latest ones are from ages ago but this is because uhh i copied all the tables from my other project so i copied all my schemas and data into my new DEV project replica and all of a sudden the cron scheduler doesnt work it says its running but no results are shown? well old results are shown from when i last ran it and when it worked with my original production project
garyaustin
garyaustin3mo ago
So that cron code as you show used to run on another instance? I always split out by cron code to a function and call that with the cron task code so I can debug with raise log in the function code.
Catto
CattoOP3mo ago
yes correct, the exact same code i copied over
garyaustin
garyaustin3mo ago
And there is nothing in the table I showed?
Catto
CattoOP3mo ago
there is nothing new its all old data in the job run details the job table does show correct, it even says its active its supposed to run every 1 minute but im not seeing any new rows which means cron is not doing its job somehow its not even calling anything, its not making a call, its not failing, its not making a new row how is that possible not to mention but there is a bug when switchin projects, and when you have edge functions page uhh selected some bug where it says client code error but that may be unrelated nayways, but idk where to go from here, i think cron itself is not working as it should
garyaustin
garyaustin3mo ago
I just ran
select cron.schedule(
'call-every-1-minute-boy',
'*/1 * * * *',
$$
raise log 'hi there';
$$
);
select cron.schedule(
'call-every-1-minute-boy',
'*/1 * * * *',
$$
raise log 'hi there';
$$
);
And it is running. It gets an error though because raise log won't work in SQL code (versus plpgsql). Is the extension enabled? I assume so if you see the cron task generated. https://github.com/orgs/supabase/discussions/30168 Here is a guide on some things to check. Restart your instance if those don't pan out. Then contact support.
Catto
CattoOP3mo ago
this shows cron jobs active
Catto
CattoOP3mo ago
No description
Catto
CattoOP3mo ago
No description
Catto
CattoOP3mo ago
select * from cron.job_run_details order by start_time DESC limit 40; see that, no new rows are being made those are old data
garyaustin
garyaustin3mo ago
Yes it looks like it is not running
Catto
CattoOP3mo ago
yea, so cron is bugged?
garyaustin
garyaustin3mo ago
No. Your instance has an issue it seems. Check out the link for debugging. Or try a restart.
Catto
CattoOP3mo ago
No description
Catto
CattoOP3mo ago
how i copied ur code
garyaustin
garyaustin3mo ago
Yes and it runs on mine. So something is wrong with your cron system. Hence the debug link.
Catto
CattoOP3mo ago
oh right, i iwll take a look thanks
garyaustin
garyaustin3mo ago
Basically the part of the guide that is relevant is to see if the schedule worker is running. And then restart the DB if not. You could just restart the db if you are not in production.
Catto
CattoOP3mo ago
No description
Catto
CattoOP3mo ago
this did return a row lol the job scheduler or cron is owned by the postgress user i checked so permissions wise i dont think is problem
garyaustin
garyaustin3mo ago
Try the restart anyway. Then contact support I guess.
Catto
CattoOP3mo ago
oh hang on a second i checked my other project and i see logs but how is that possible if im running it from the other project
garyaustin
garyaustin3mo ago
It is not possible.
Catto
CattoOP3mo ago
oh thats what im seeing xD
Catto
CattoOP3mo ago
No description
Catto
CattoOP3mo ago
those are all from today yea
garyaustin
garyaustin3mo ago
Then you are setting and looking in two different instances.
Catto
CattoOP3mo ago
hang on a second am i right? are those from today oh they are, but the time is off, that says 5pm its 9pm right now, so those are old as well
garyaustin
garyaustin3mo ago
So cron was working 4 hours ago on the system.
Catto
CattoOP3mo ago
ah i might have ran it 4 hours ago on my the other project then but the other one still aint working ever
garyaustin
garyaustin3mo ago
Did you restart the DB?
Catto
CattoOP3mo ago
ah lemme check how do i do that i hope that fixes it its restarting rn lmao i really hope thats the fix still aint working nooooooooooooooooooooooooooooooooooooooo can i uninstall cron somehwo or reinstall it why is cron acting up
garyaustin
garyaustin3mo ago
You can try that in the extensions tab of database. If you are not getting any errors in the Postgres logs then you'll have to contact support. Not much users here can do unless we missed something obvious you are doing wrong.
Catto
CattoOP3mo ago
theres no way i did something wrong, i copied ur code, i ran the cron scheduler exactly the same, so its basically 1-1 you know something, my pg cron was already installed in the other project? is cron seperate for each project? like i swear down, the pg cron was already installed in the other project that i setup hmmm, so maybe osmehow, the two projects crons are already interlinked and its messing something ujp
Catto
CattoOP3mo ago
No description
Catto
CattoOP3mo ago
not to mention i get this error switchin projects when at the edge function page although thats probably a seperate bug?
garyaustin
garyaustin3mo ago
Is your extension on? I assume it was as you did get the task in the queue. I have no idea what that is and I toggle projects (4 or 5) all day long.
Catto
CattoOP3mo ago
yea i checked extensions both projects have same extensions you never seen that before? it shows up 100% of the time for me when i switch projects, and im at the edge functions page
garyaustin
garyaustin3mo ago
No errors in dashboard on firefox/chrome windows 11. Not done it from the edge functions page.
Catto
CattoOP3mo ago
sorry i mean sql editor i run the schedules from my sql editor and when i swithc projects when at the sql editor it bugs out with sorry unexecpted error kay i sent a suppor trequest for that bug issue, but i think im seeing two bugs then LMAO the client side bug + cron bug ah i got an email saying free plan may not be looked at damn it well now what should i uninstall the pg cron from my other project extensions
Catto
CattoOP3mo ago
No description
Catto
CattoOP3mo ago
LOOK AT THAT BS new row was made but only on my original project not the replica i made so my original project works, but the new one i made, it completely is messed up and not working why is that
garyaustin
garyaustin3mo ago
You just mentioned replica...
Catto
CattoOP3mo ago
by replica i mean i created a new project and ran the... commands to copy schemas and tables manually made new project but rna some commands to copy the stuff over
garyaustin
garyaustin3mo ago
OK not branching or read replicas.
Catto
CattoOP3mo ago
nope ah i used pg_dump to dump the stuff pg_dump and pg_restore
garyaustin
garyaustin3mo ago
I have no idea at this point.
On your SQL editor thing... Are your instances in the same org?
Catto
CattoOP3mo ago
yes in same org
Catto
CattoOP3mo ago
No description
garyaustin
garyaustin3mo ago
I don't do that with Free instances as they both then share the same free limits.
Catto
CattoOP3mo ago
i didnt know that but one is dev version anyways
garyaustin
garyaustin3mo ago
So I just tried 2 instances in the same org and I see how the SQL thing can get really messy. It keeps the SQL from one to the other. I always have to go to an intermediate screen or use two tabs for my instances.
Catto
CattoOP3mo ago
so knowing they are in the same org is the problem?
garyaustin
garyaustin3mo ago
Not your cron issue directly.
Catto
CattoOP3mo ago
but why is one project cron working and other not?
garyaustin
garyaustin3mo ago
But I can see how easy it would be to run the SQL on the wrong instance. I have no idea. We have debugged what I know to debug.
Catto
CattoOP3mo ago
damn it, well.................. s i guess i will just run the cron job from my other project? i mean all its doing is calling an api so it wouldnt even matter which one its from the cron running
garyaustin
garyaustin3mo ago
You could pause the "bad" instance. And start a new instance. Don't do anything but turn on Cron (if not on by default) and see if it works there. Still does not solve what is wrong with your new instance though.
Catto
CattoOP3mo ago
yea true hmmm what you mean by pausing the bad instance how would i pause the cron
garyaustin
garyaustin3mo ago
Pause the instance. Just saying you can check the code on a new instance before doing anything else but the SQL for your cron task to point to a bad instance OR you are doing something or did something we did not find. I don't recall ever encountering an instance cron not working after restart of the DB.
Catto
CattoOP3mo ago
yea i must be a first for cron not to work i guess thats not a good thing so what does that mean... hold on a second, should i try restarting my other project? becuase maybe its using the other projects cron 1 org has 1 cron? i dont understand, these projects are basically identical and 1 has broken cron i can barely even cacess the sql editor coz of that client editor bug okay i guess i will just run my cron on my other project that works i hope they fix this issue i guess, but they probably wont look at it for like months
garyaustin
garyaustin3mo ago
No each project/instance has it is own cron task. It is part of Postgres database and each project has its own database. All an org shares is billing metrics.
Catto
CattoOP3mo ago
@garyaustin chat gpt solved the issue lol it told me to run some pg cron uhhh reinstalling commands and it said pg dump and restore is what broke the cron
garyaustin
garyaustin3mo ago
Do you have those reinstalling commands?
Catto
CattoOP3mo ago
-- Drop and reinstall the pg_cron extension drop extension if exists pg_cron cascade; create extension pg_cron; ⚠️ Warning: This will delete all current cron jobs on that project.

Did you find this page helpful?