R
Railway

✋|help

go-cron jobs not running in railway

A.atran258/27/2023
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()
}

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?
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
A.atran258/27/2023
f9c5389b-b1b9-4d0d-98a7-46d867371f65
BBrody8/27/2023
hey I use that package in my projects
Solution
BBrody8/27/2023
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?
BBrody8/27/2023
gocron.NewScheduler(time.UTC)
A.atran258/27/2023
Sure, let me try that out right now
Okay yup that fixed it. Thanks for the speedy help!
BBrody8/27/2023
no problem! did you want to hear my possible solution that would allow you to use time zones?
A.atran258/27/2023
sure if you have a possible solution I'd love to hear it
BBrody8/27/2023
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
A.atran258/27/2023
ahh interesting, alright let me try that out
importing the time/tzdata did indeed fix the issue fully
BBrody8/27/2023
awesome
A.atran258/27/2023
thanks for all the help!
BBrody8/27/2023
no problem!

Looking for more? Join the community!

Recommended Posts
pnpm not foundHi! I'm having trouble building my app, and haven't had success with any of the suggestions with othDo you guys have prepaid options?Say I pay 5$ once and I get to use those 5$ worth of resources all year round. I'd rather do that thChange Heroku to RailwayI need more info because I have a problem with Heroku with my hosted proyect there WebSocket doesnt I am getting this error on my deployment```console GET failed with status code 403 (a proxy could be disallowing the use of 'Upgrade: derp')Flask app wont work with port 0.0.0.0application not respondingmemory usage doesn't decreasememory usage of one of my python processes was instantly increased to ~2700 mb, it was my mistake, bAutomated Postgres backup onto a volume ?Since now the project I was developing for a while is almost ready for production, we need to make show can i deploy my vue projecti get this errorHosting Django backend and React frontend from the same DomainI have two services, one for my backend and one for my frontend. They currently have two separate doResponse Pending with OpenAIHi I have SAAS website running on Railway using OpenAI with Next js , the problem is the endpoint noDjango backend fails to respondWhen I click on the url for my django backend (I am using react frontend in a separate service) I geReflexHi, someone deploy reflex.dev in railway? do you have a guide?The new log explorer is great, Is it possible to show the service name in there ?Currently in the log explorer the service name is an ID and I was wondering if you plan to show the What is a good / recommended resource use for a web app? Plus question about scaling.I am deploying a few applications for a client of mine. It is a multi-tenant app made in sveltekit. How to put site on maintenance mode in railway?hello everyone how do i put a site on maintenance mode in railway or 'page can not be reached' mode Service not updating to Hobby specshey! I don't know if I'm doing something wrong but I paid for the hobby plan but my service still haerror on index fileI have an index file in a folder that exports all the components in that folder for easier importinOdoo Community EditionI would like to know if we can setup Odoo in railway? The odoo image is built with docker using thiWebsocket disconnectingHey, I have an app that uses a websocket (hosted on railway) but for some reason every once in a whinpm WARN config production Use `--omit=dev` instead when trying to start Nestjs appI'm trying to deploy my app (https://github.com/Omniforce-Technologies/omniforce-asset-store/tree/de