Cron job to run script: Add separate service or not?
Hi, I have a website running on railway with django and a postgress database. I have a separate python script in the same repo as the Django project that updates the postgres database (that is also used by the main django project) with some external data. I want to run this script once a week, separately of the main service (which should always run). I saw you can use a cron job to schedule a job to run. However, if I add a cron job to my main service (which runs the website backend), it would run that service's start command instead. I could add a new service for running this job, but i'm not sure if I should add the same github repo twice as two separate services (that both run django to interact with the same postgress database service). What would be the recommended way to do this? Thanks in advance!
Project id: b1e4979e-4e81-4258-ab74-dde97491a4ec
Solution:Jump to solution
two services from the same repo would be the correct way to go. on the cron service you would set the applicable start command so that the cron job runs the script
7 Replies
Project ID:
b1e4979e-4e81-4258-ab74-dde97491a4ec
Solution
two services from the same repo would be the correct way to go. on the cron service you would set the applicable start command so that the cron job runs the script
make sure your script exits as soon as its done though
@Brody I see, thanks. When I set up the separate service, can I also manually run it (at some other time than the scheduled cron time)?
yes a cron service gives you a
run now
buttonPerfect, thanks so much (for the incredibly fast response as well!)
no problem!