20 days ago
I have a python web site service connected to a repo that's working great.
Now I want to setup a Cron job to run a command on a weekly schedule. Best I can tell from documentation and searching central station the way to do this is to add a service that points to the same repo and have the start command for that service invoke the command (python manage.py commandnamehere).
So....I created a new service, pointed to same repo, added the python manage.py <command file> as start command, and entered the cron expression.
I used the run now button to test the service and it crashed probably because 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 working service 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.
5 Replies
20 days ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
20 days ago
Hello,
Yes it likely crashed because you didn't give the CRON service the variables the code needs.
You can indeed duplicate a service, that's done by right clicking a service and selecting the duplicate option, then you can set the needed CRON schedule and start command.
It's not going to be expensive at all, you will only be charged for the time the CRON job is actually running, and even so, you will only be charged for the resources your code uses, say if your code only runs for a few minutes and uses 0.1 vCPU and 200MB then that's going to only cost a few cents, if that.
Best,
Brody
Status changed to Awaiting User Response Railway • 20 days ago
19 days ago
I duplicated the service and removed the web URLs thinking two instances with same URL might be problematic.
Once the service deployed it worked by "run now" and by schedule.
I used "expensive" metaphorically...wasn't concerned about the $$ but about the time & overhead of configuring, building, and deploying multiple instances of the same repo just to run some Cron Jobs. I'm new to this world and I can see that it's not that hard to do it this way. I just wonder if there are other more efficient approaches.
Status changed to Awaiting Railway Response Railway • 19 days ago
19 days ago
I'm curious to know what isn't efficient about the approach of duplicating a service and setting its cron and start command.
Status changed to Awaiting User Response Railway • 19 days ago
17 days ago
well...I don't know enough about the details of the entire system to really know what I'm talking about but what I was wondering about is (1) each cron job will require building and deploying the container each time I update my code so didn't I just doubled the amount of build resources? each additional cron job adds the same. (2) do these builds take up space somewhere? they each might be small but again each instance is a complete copy...I'd think they add up.
I also don't know what the alternative would be...
I'm happy whatever the answers are...just curious about how things work. Thanks for all your help!
Status changed to Awaiting Railway Response Railway • 17 days ago
Status changed to Solved beballod • 17 days ago