Cron job to schedule Python script
I successfully deployed my main application script as a API, but now I would also like to schedule some cron jobs to run python scripts. What am I doing wrong? It is not working for me. This is my railway json file:
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "python application.py",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
},
"cron": {
"job": "0 0 * ? * ",
"command": "python zera_consultas.py"
},
"cron": {
"job": "0 0 ? * *",
"command": "python desbloqueia_usuarios.py"
}
}
24 Replies
Project ID:
N/A
N/A
I'm curious as to how you came up with this railway.json file, because that is not a valid config
really? why not? I got it with a friend and it is working (without the cron part). is something wrong?
the cron stuff isn't valid, there's nothing relating to cron that you can configure in the railway.json file
what made you think that the cron stuff was valid?
oh! damn 😦 is there any way to schedule in railway app then?
I got it on a stackoverflow post, but is wrong apparently =[
very wrong
(this post: https://stackoverflow.com/questions/75889034/error-creating-cron-job-for-python-script-on-railway)
Stack Overflow
Error creating cron job for Python script on Railway
I'm trying to run a Python script on Railway.app, every 30 seconds, but it's not working. I tried with the codes below inside my project, but it seems to me that there is something wrong that doesn't
bruh you can't use code from the question itself
i took what i could LMAO
railway has no native cron scheduler, you would need to use the schedule python library in code
so I would do it within the main script?
with the schedule module
correct
thanks 🙂
are you related to the railway owners? or a community contributor?
my dad is the owner of railway
huh really
no
._.
just a community member
ask them for money
for helping the members
😮
they give me 1$ for every thread I solve
I tried: schedule.every().hour.do(zera_consultas)
but i dont think it is working =/ have i done something wrong?
that looks fine to me. Why don't you think it's working? Have you tested it locally?
ok i understood how it works now thanks
how do I mark this as solved?