Railway cron schedule skipped
Project ID: 5510af11-7ac6-4c46-b964-e91edd728850
This morning my cron schedule didnt run at 10 as planned (see attached)
The logs show the below message and the cron job is shown as "active". The error message is typical and doesnt normally stop the git repo from running.
Could anyone suggest why the code didnt execute? Quite new to this
16 Replies
Project ID:
5510af11-7ac6-4c46-b964-e91edd728850
update: this cron task just completed but it took 3 hours to run instead of 30 seconds. any ideas why this could happen?
you're running a bot in a cron schedule?
Yeah it’s just a custom discord bot that posts some information at fixed intervals
bots are usually made to run in a constant event loop, if you do insist on closing it each time over just an internal cron in your code
make sure you close your discord event loop
i use this myself py to cron every day at 6 AM, be wary of railways timezone in UTC, if you are on a different timezone it will cron on its correct time but incorrect for your timezone
oh i see you're on .js, my bad if you want me to write a nodejs version let me know but its pretty similair
@Morpheus thanks for taking the time bud
i've attached my git code which seems to run pretty well when its triggered within railway and im using Railways native cron scheduler to execute the js from my github repo
what i dont understand is what triggers the code to run, is it permanently active once deployed? i believed i needed to use an external scheduler to run the script.
very new to this as you can tell and first time coding in js
this is the cron schedule in railway
sorry for all the debugging being included, the js is much simpler than it appears
can you tell us why you are running your bot at those specfic times and not 24/7?
The bot is hosting a competition where new challenges need to be posted at discrete intervals. I wasn’t aware of how to keep the script running 24/7 so opted to schedule it to run every 6 hours posting some corresponding data from a postgres db
If it was running 24/7, what would the trigger be to post at the correct times?
I have sent you
The code in Py of how i handle this
In simple english,
you initialize an event loop that just runs infinitely and you define 4 CRON times
now in this event loop you just constantly compare the current time with one of the 4 CRON times,
when your CRON is triggered you can cache or save the time of triggering somewhere so now in the beginning of your script you just check if the last run time was <24 hrs ago to avoid firing the CRON multiple times
and you just do this for all 4 of your times
im sure NodeJs has libraries for this too but this is a high level overview
.
Thanks dude
if you need help with the code in nodejs let me know ill code it for u
It’s good practice for me in js