R
Railway•11mo ago
BlazingIce

Help with cron job in flask and postgres

My /api directory is: /api |-- models.py |-- app.py |-- config.py |-- cron.py I want to run a backend server and a cron service seperately. Backend builds and works. cron.py imports from models and config. How can I create a service that only runs cron.py? Is it something with railway.toml?
18 Replies
Percy
Percy•11mo ago
Project ID: 2ae4d6f5-aff1-40bc-926b-a21bfce1ede0
Percy
Percy•11mo ago
Project ID: 2ae4d6f5-aff1-40bc-926b-a21bfce1ede0
BlazingIce
BlazingIceOP•11mo ago
2ae4d6f5-aff1-40bc-926b-a21bfce1ede0
Brody
Brody•11mo ago
new railway service, set the root directory to /api and set a start command to python cron.py
BlazingIce
BlazingIceOP•11mo ago
Got it to run once, when I put in a cron schedule (I put * * * * *), it doesnt actually save the schedule
Brody
Brody•11mo ago
you are using an in code scheduler, don't use railways cron
BlazingIce
BlazingIceOP•11mo ago
is it better to use railway's cron or my own scheduler because i tried to switch to railways cron which one would be more efficient?
Brody
Brody•11mo ago
strictly speaking, railways because that means your code isn't running 24/7, but that requires code changes and since you are already using an in code scheduler I don't advise you to change things
BlazingIce
BlazingIceOP•11mo ago
actually just saw another post where railway's cron cant run more frequently than 5 minutes thanks for the answers!
Brody
Brody•11mo ago
may I ask how frequently your in code scheduler is running?
BlazingIce
BlazingIceOP•11mo ago
every minute
Brody
Brody•11mo ago
cool
BlazingIce
BlazingIceOP•11mo ago
also would having flask as development be more costly to run
Brody
Brody•11mo ago
yes, you want to use gunicorn
BlazingIce
BlazingIceOP•11mo ago
im using gunicorn already but also in my code ive used: if os.environ.get("FLASK_ENV") == "production": and it doesnt run as true, can i be using gunicorn and also not in production?
Brody
Brody•11mo ago
have you set a service variable FLASK_ENV to production ?
BlazingIce
BlazingIceOP•11mo ago
😅 no thanks for the help!
Brody
Brody•11mo ago
no problem, now lets hop over to your previous thread so we can get you not running a development server for your frontend
Want results from more Discord servers?
Add your server