Cron jobs with Django

What is the way to setup cron jobs with django on railway? I tried the usual way of dockerizing my app but docker compose isnt supported on railway. What other options do I have? (Newbie here, came from using heroku scheduler)
7 Replies
Percy
Percy2y ago
Please provide your project ID or reply with N/A. Thread will automatically be closed if no reply is received within 10 minutes. You can copy your project's id by pressing Ctrl/Cmd + K -> Copy Project ID.
Percy
Percy2y ago
⚠️ experimental feature
Percy
Percy2y ago
No project ID was provided. Closing thread.
Nahasco
NahascoOP2y ago
be4c5d11-a107-4bc2-b215-df55f2e73277
jackson
jackson2y ago
would recommend APScheduler, you can use cron expressions if you would like you can just add it as a dependency alongside django, in my repo i have a config.py file that lays out the configuration for gunicorn and also has some cron jobs in it
# imports n stuff

# gunicorn config here

def on_starting(server):
scheduler = BackgroundScheduler()
scheduler.add_job(function_name_without_parentheses_here, 'cron', hour=16, minute=0, second=0, timezone='America/Los_Angeles')
scheduler.start()
# imports n stuff

# gunicorn config here

def on_starting(server):
scheduler = BackgroundScheduler()
scheduler.add_job(function_name_without_parentheses_here, 'cron', hour=16, minute=0, second=0, timezone='America/Los_Angeles')
scheduler.start()
Nahasco
NahascoOP2y ago
thanks for the reply can i set management commands as the cron job function?
jackson
jackson2y ago
hmmmmmmmm that might get tricky if you're talking about python manage.py commands you could try just calling them via the shell with os.sys but beware of conflicts with the db and stuff if it's in use by the application at the time
Want results from more Discord servers?
Add your server