Service with cronjob in language-level library not executing properly.
mecies
TRIALOP

2 years ago

Hey, I have a small service that I built for learning purposes that has a scheduler with a cronjob executing every day at 2 PM.

When I deploy the service to Railway, the cronjob timing is off, it executes every 14th minute of every hour.

Do you have any idea why would that be?

Link to repository
https://github.com/mecies/go-daily-eur-to-pln/blob/main/main.go#L11-L37

Solved

5 Replies

2 years ago

Seems like a timezone confusion - are you expecting this to run everyday at 2PM UTC? All server time on Railway is in UTC.


mecies
TRIALOP

2 years ago

Yes, I am expecting it to run in UTC.
I don't see how it could be timezone confusion, in the code that I linked, it can be seen that the cronjob is configured as "0 14 * * *" which represents 2 PM every 24 hours.

If it was a timezone confusion, it would still be every 24 hours just at a different time.
My issue is that the job is triggered every hour like 01:14, 02:14, 03:14, and so on, and I wonder if it could have anything to do with the hosting.


2 years ago

According to the cron expr format of the library you're using [0], 0 14 * * * means "0 second, 14m, every hour, every day" so it would match up to what you're seeing.

[0] https://pkg.go.dev/github.com/robfig/cron#hdr-CRONExpressionFormat


Status changed to Solved Railway almost 2 years ago


mecies
TRIALOP

2 years ago

Thank you @rc, you just found a bug in my code and it was not a Railway issue. Have a great day 🙏


2 years ago

Happy to help!


Loading...