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
Chaika
Chaika12mo ago
If you navigate to your worker in the dashboard, then "Logs" and then "Past Cron Events", what do you see?
Neiki
Neiki12mo ago
Neiki
Neiki12mo ago
Neiki
Neiki12mo ago
could it be the high cpu time ?
Chaika
Chaika12mo ago
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
Neiki
Neiki12mo ago
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
Chaika
Chaika12mo ago
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
Neiki
Neiki12mo ago
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
Neiki
Neiki12mo ago
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.
Neiki
Neiki12mo ago
Neiki
Neiki12mo ago
you can see the difference here
Chaika
Chaika12mo ago
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?
Neiki
Neiki12mo ago
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.
Chaika
Chaika12mo ago
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
Neiki
Neiki12mo ago
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
Chaika
Chaika12mo ago
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
Neiki
Neiki12mo ago
ah okay thanks you have actually showed me something i complete missed... i though i somehow broke cron triggers but it was just me NotLikeThis 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!!! ❤️
Neiki
Neiki12mo ago
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!