Cron Triggers running twice!!!!!
sometimes my cron triggers execute twice and then skip one,
f.ex i have an cron trigger running every minute that runs an function and does stuff.
5 minutes all is fine and its execution every minute just fine, but then randomly it skips a minute and then it runs twice in the next minute but with the same message (i attach ids to my cron executions to track) and they both have the same id, how can this happen? 🤔 i watched the logs and i saw the crons actually triggers twice in one minute, after that then it works normal again, then it happens again
an example is in the image
i also tested with 5 and 10 minutes but the same
how can i fix
18 Replies
If you navigate to your worker in the dashboard, then "Logs" and then "Past Cron Events", what do you see?
could it be the high cpu time ?
those don't look like double triggers to me. The CPU time is a bit high, but if you check your Metrics -> Median CPU Time, if your p50 is below 50ms (paid) I believe you should be fine. It wouldn't be causing double triggers though. If it was erroring out, you'd see error status instead of success
okay i try to change some things and test, if something happens again i will update here again.
also i want to ask if it would be good for you if i could ping you then once after im back, if not i wont do
Sure, if it's worth mentioning as well, Cron triggers can be a bit slow to update/have issues updating sometimes. If you changed your cron schedule, it can take up to 30 minutes to update.
There has been issues with crons double triggering before, but it's always shown as double in that cron log there, and I have ~7 or so crons personally once a minute, and none of them are doubling, so not sure
i use wrangler to publish my worker, if i update the cron triggers in my .toml it doesnt remove them on the dashboard, i have to remove them manually. idk somehow i have some problems with cron triggers.
i changed now alot in my code to reduce the cpu time alot, maybe that changes something. Thanks for the infos
f.ex here, the cpu time is on max 5-10 seconds, and i dont have double crons and it works perfectly fine, but as you can see i have sometimes HIGH cpu usage i mean its more than normal and then it starts to trigger twice.
you can see the difference here
i use wrangler to publish my worker, if i update the cron triggers in my .toml it doesnt remove them on the dashboard, i have to remove them manually. idk somehow i have some problems with cron triggers.Sounds like it could be related, if you had an old one. Might have been a bit of an overlap period where both were active
f.ex here, the cpu time is on max 5-10 seconds, and i dont have double crons and it works perfectly fine, but as you can see i have sometimes HIGH cpu usage i mean its more than normal and then it starts to trigger twice.What does the worker do?
should i try to deploy my worker again but this time connect to my github repo? and doesnt use wrangler etc? 🤔
it fetches to different apis to summarize it to one in a page, stores them in a KV etc (simplified)
if the api doesnt return valid (whats the case now because of other api quota limits) it just breaks at the start, thats why its only like 3 or 5 ms cpu time, but ofc if it gets valid response from all it can go up to 10-20. I made a big mess in my code so it somehow went up to 70-90ms what i "hopefully" now fixed.
should i try to deploy my worker again but this time connect to my github repo? and doesnt use wrangler etc? 🤔I was talking specifically about having duplicate crons
if the api doesnt return valid (whats the case now because of other api quota limits) it just breaks at the start,ah that makes more sense why the variation
ups ah get it, so if i deploy and change cron triggers settings in my wrangler i just need to wait some minutes and then it should fix the dashboard settings?
and yeah i will test it and will just update this post if something happens again, currently no problems at all
nah I'm not saying it would fix itself, just saying there is general lag in updating cron settings (it will show in the dashboard fine, but just not execute fine), seems likely that if you had two at one time and then deleted one, there still might have beena point where both were executing
ah okay thanks you have actually showed me something i complete missed... i though i somehow broke cron triggers but it was just me for the lots of messages but i needed to handle this now since along time ago
if i see something happen again i will come update this post! if not big big thank you to you!!! ❤️
i can happily say it was the high cpu ms time, i now fixed it and got now duplicated cron trigger or any problem thanks!