R
Railway

✋|help

Cron Jobs

Nn131mg9/9/2023
Hey everyone. I'm moving from Vercel to Railway so this is my first Railway project. I'm trying to implement a replacement to Vercel Cron jobs, ie: I have an API I need to call every so often as part of a timer. This is a NextJS app. Under Project Settings > General there is the "Cron Schedule" section, but as best I can tell that's going to redeploy my app on that schedule, not execute a piece of code on that schedule. Am I missing something silly here? I suppose I could build a completely separate service to run my cron jobs but that seems like overkill.

To the extent that it matters, I haven't upgraded to Pro yet, I was just doing the dev on the Hobby plan (in case I need a feature behind the paywall of Pro for this to work).
Nn131mg9/9/2023
c87c74c6-772c-4bd2-9d34-0fc2fc173ea8
BBrody9/9/2023
you would want to make a new service, set the start command to what you want to run on the schedule and then set the cron expression
Nn131mg9/9/2023
gotcha... ok let me play around with that and see if I can get that working
BBrody9/9/2023
just make sure whatever you run does it's thing and exits as soon as it's done
Nn131mg9/9/2023
how does the infrastructure handle if it's still running when the next execution time comes up?
BBrody9/9/2023
I think it skips it
at least that's what a changelog has said, there has been some debate on that though
Nn131mg9/9/2023
I assume I can share environment variables across multiple services in that one project so that I'm not duplicating places where the same keys exist?
nevermind, I see
BBrody9/9/2023
you can do shared environment variables, or you can do reference variables
Nn131mg9/9/2023
I just have to move the variables from the actual service where they live today to the Shared Variables thing
BBrody9/9/2023
nah I recommend using reference variables
BBrody9/9/2023
you set this variable on your cron service and when the cron task is ran, the environment variable VAR_1 will be rendered to the same variable name as the variable it references
VAR_1=${{<service name>.VAR_1}}
and yeah those are the docs for this type of thing, so definitely give them a read
Nn131mg9/9/2023
awesome, ok thanks!
I'll leave this open for a little bit in case I've got follow up questions, thanks for the push in the right direction!
BBrody9/9/2023
absolutely! come back if you have any more questions!
Nn131mg9/9/2023
I think I have this working, but there's some odd behavior... it appears to run my code only when the cron schedule triggers it...
Nn131mg9/9/2023
Nn131mg9/9/2023
the 13:45 it triggered, and it "completed"
but if I click Run Now or trigger a new build through Github, it shows "Success" but it doesn't actually run anything
BBrody9/9/2023
what makes you think it didnt run anything when you trigger it manually?
Nn131mg9/9/2023
there's nothing in the logs
it's literally just a one-line script that does a console log... the log message shows up on the 15 min executions, but not if I click Run Now
good news is all the environment variable stuff worked just as you said, super easy
🙂
yeah, it just ran again at the top of the hour and that completed and logged my message... it's almost like clicking "Run now" does something different than when the cron schedule triggers it.
but at least I've got it working 🙂
BBrody9/9/2023
okay that seems like a bug, it still may be running it, just logs arent getting piped through
DDuchess9/11/2023
Thread has been flagged to Railway team by @Brody.
BBrody9/11/2023
@gschier - no logs when triggering a manual run of a cron job
Ggschier9/19/2023
Hmm, that's strange. And it happens every time? I added a task to take a look this week
I just fixed a couple bugs around crons. You may have to issue a redeploy to kickstart it

Looking for more? Join the community!

Recommended Posts
How to connect FastAPI with Planetscale (mysqlclient error)Hey, how are you guys doing? I have a backend on Railway who is running with FastAPI (using this teHobby PlanI have a Discord bot which needs to be hosted, I had it hosted on railway before the recent pricing AttributeError: 'DatabaseWrapper' object has no attribute 'set_schema'I'm using django with mutlitenants using the package django-tenants==3.5.0 When i deployed the app tHosting errori am hosting my discord bot written in python using nextcord library and when i deploy it then it shDeploy angular applicationerror: ```2 minutes ago via GitHub Init main View Logs Removed Deployed 3 minutes ago vimongo on railwayI am trying to get mongo v7 up and running on railway. When using default options, I am getting follTCP Proxy timeoutI'm trying to start a Redis server with the official Docker image from Docker Hub with #TCP + LogginHow to move from Working Localhost w/ Django Websockets to Railway production?I had a functioning django websocket fantasy draft on my local host using daphne and redis. However,There's suddenly two new random columns in my database??I went in and checked my railway dashboard and to my surprise there's two new completely random dataRailway having issues with Mongoose NPM package???Locally my code works fine, I can connect to Mongo using Mongoose no issues but when on Railway it rNo VAT taxes on invoicesHello everyone I've just joined this server. On my invoices, I don't see any VAT tax prices includeIssue with mounting volumeHello, I have an instance of n8n running, I need to attach a volume to keep community node persistenPin memory usageI'm running a service that scales memory usage unpredictably and quickly, and it crashes in these caVariables redeploy infoSometimes when I don't have an active deployment and I change the variables it triggers a redeploy bStatic IPsIs there any updates for static IPs? I would love to use Railway for a Discord bot so everything is Prebuilt Mqtt Service and PortsLooking for some guidance. Currently have a couple different services in my project, including a posMySQL queries timeout or lead to blank screen on web versionFor the last 2 days or so I've been running into some problems with my personal project database. ItAdonisjs Migration - MySQL using password noTrying to deploy an app on railway with adonisjs and a MySQL database, I can get the web app runningGraalVMHi, is it possible to build a graalvm image in nixpacks? https://github.com/railwayapp/nixpacks/issuDebugging issuesIs their someway to get into filesystem so I can debug production errors a0aaa94d-45ad-410c-bcae-31