2 years ago
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
1 Replies
2 years ago
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
2 years ago
make sure your script exits as soon as its done though
<@539512869780455445> 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)?
2 years ago
yes a cron service gives you a run now button
2 years ago
no problem!
a month ago
I've got a similar problem but this solution did not work. I have a Python / Django project in my repo and want to run a python command in the repo once a week. I created a new separate service, pointed to same repo, added the python manage.py <command file> as start command, and made the cron setting.
I used the run now button to test it and it crashed 'cause it didn't see the database the code refers to. I'm guessing the new service didn't have all the same variables and database connections needed by the command.
Can I create this service by duplicating the current instance and editing it?
Is there a better way to do this than duplicate the entire repo to run one script? I may end up with more than one Cron job and this seems expensive.