R
Railway16mo ago
.atran25

go-cron jobs not running in railway

Hello, so I'm using the go-cron(https://github.com/go-co-op/gocron) library for managing my cron jobs on my Go web server.
func CharactersIdWeeklyCron() {
// Cron job for adding character ids every Wednesday at 4am PST
cron := gocron.NewScheduler(time.FixedZone("America/Los_Angeles", (-8 * 60 * 60)))
cron.Cron("0 4 * * 3").Do(func() {
dfo.FindCharacterStats()
})
cron.StartAsync()
}

func CharactersStatsDailyCron() {
// Cron job for adding character stats every day at 3am PST
cron := gocron.NewScheduler(time.FixedZone("America/Los_Angeles", (-8 * 60 * 60)))
cron.Cron("*/15 * * * *").Do(func() {
dfo.UpdateCharacterStats()
})
cron.StartAsync()
}
// Setup CRON jobs
if os.Getenv("CRON_ENABLE") == "true" {
l.Info().Msg("Setup CRON jobs")
cron.CharactersIdWeeklyCron()
cron.CharactersStatsDailyCron()
}
func CharactersIdWeeklyCron() {
// Cron job for adding character ids every Wednesday at 4am PST
cron := gocron.NewScheduler(time.FixedZone("America/Los_Angeles", (-8 * 60 * 60)))
cron.Cron("0 4 * * 3").Do(func() {
dfo.FindCharacterStats()
})
cron.StartAsync()
}

func CharactersStatsDailyCron() {
// Cron job for adding character stats every day at 3am PST
cron := gocron.NewScheduler(time.FixedZone("America/Los_Angeles", (-8 * 60 * 60)))
cron.Cron("*/15 * * * *").Do(func() {
dfo.UpdateCharacterStats()
})
cron.StartAsync()
}
// Setup CRON jobs
if os.Getenv("CRON_ENABLE") == "true" {
l.Info().Msg("Setup CRON jobs")
cron.CharactersIdWeeklyCron()
cron.CharactersStatsDailyCron()
}
https://i.imgur.com/HNMzeif.png So this is what my cron jobs look like and how I initialize them in my app. The daily job is set to run every 15 minutes just for testing. It runs fine on my local machine, but doesn't seem to run any jobs on railway deployment. It does seem to setup the cron jobs though as can be seen by logs in the screenshot. Would you guys happen to know what could be the reason?
GitHub
GitHub - go-co-op/gocron: Easy and fluent Go cron scheduling. This ...
Easy and fluent Go cron scheduling. This is a fork from https://github.com/jasonlvhit/gocron - GitHub - go-co-op/gocron: Easy and fluent Go cron scheduling. This is a fork from https://github.com/j...
Imgur
Solution:
I always use UTC on the scheduler because it makes the most sense for server stuff, can you try to initialise each scheduler with UTC?
Jump to solution
13 Replies
Percy
Percy16mo ago
Project ID: f9c5389b-b1b9-4d0d-98a7-46d867371f65
.atran25
.atran25OP16mo ago
f9c5389b-b1b9-4d0d-98a7-46d867371f65
Brody
Brody16mo ago
hey I use that package in my projects
Solution
Brody
Brody16mo ago
I always use UTC on the scheduler because it makes the most sense for server stuff, can you try to initialise each scheduler with UTC?
Brody
Brody16mo ago
gocron.NewScheduler(time.UTC)
.atran25
.atran25OP16mo ago
Sure, let me try that out right now Okay yup that fixed it. Thanks for the speedy help!
Brody
Brody16mo ago
no problem! did you want to hear my possible solution that would allow you to use time zones?
.atran25
.atran25OP16mo ago
sure if you have a possible solution I'd love to hear it
Brody
Brody16mo ago
import _ "time/tzdata" this will embed time zone data into the build I assume whatever container railway is running your app in is missing the timezone data and the underscore is very necessary
.atran25
.atran25OP16mo ago
ahh interesting, alright let me try that out importing the time/tzdata did indeed fix the issue fully
Brody
Brody16mo ago
awesome
.atran25
.atran25OP16mo ago
thanks for all the help!
Brody
Brody16mo ago
no problem!
Want results from more Discord servers?
Add your server