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
Project ID:
2ae4d6f5-aff1-40bc-926b-a21bfce1ede0
Project ID:
2ae4d6f5-aff1-40bc-926b-a21bfce1ede0
2ae4d6f5-aff1-40bc-926b-a21bfce1ede0
new railway service, set the root directory to
/api
and set a start command to python cron.py
Got it to run once, when I put in a cron schedule (I put * * * * *), it doesnt actually save the schedule
you are using an in code scheduler, don't use railways cron
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?
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
actually just saw another post where railway's cron cant run more frequently than 5 minutes
thanks for the answers!
may I ask how frequently your in code scheduler is running?
every minute
cool
also would having flask as development be more costly to run
yes, you want to use gunicorn
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?
have you set a service variable
FLASK_ENV
to production
?😅 no
thanks for the help!
no problem, now lets hop over to your previous thread so we can get you not running a development server for your frontend