There will always be differences between environments: development mode/Local, production mode/Render, etc. These differences need to be considered and configured as required for your own app in each environment.
If youāre using a free Web service, this will spin-down after 15 minutes of inactivity, meaning your scheduler process would no longer be running. When a new request comes in, a free web instance will be spun up. More on this in the docs.
Scheduled tasks/jobs are better suited to Renderās dedicated Cron Job service, or if you want to use your own queue/scheduler a Background Worker. However, these service types donāt have a free offering.
Since it is a personal project, I wasnāt willing to pay for it to work but I am still curious to see it live.
What should I understand from the offer since it is paid per time, would I pay everytime the cron job is worked or the time my cron job takes to be done ?
The idea was to run the job once a day to generate new maps daily.
From what I understand, I canāt execute a Cron Job from a python code right ? Only commands ?
But if the script is part of my web app, should I run the whole app via a Cron Job or make it separate ?
If so, would creating a simple scheduler.py with a call to the function inside of my repository (that contains the whole app) be sufficient and allow me to use a command ?
I am a bit confused on how the Cron will affect my web app still, do I simply need to add my database into the environment variables of my Cron ?
Services are separate, but you could deploy the same repo to both a Web Service and a Cron Job. Then the difference would be to call what you need, e.g. Web Service Start Command = start a web server, Cron Job Command = call a script.
The Cron Job could access a database in the same way as your Web Service, e.g. env var with a connection string.
I think I understand better now but i still have some doubts concerning how would the cron job run and ātalkā with my app.
I am using Flask as a framework for my app.
I initialize the DB in the app and the function Iād like to schedule starts like this :
def generate_and_save_maps(difficulties_to_rerun=None):
with app.app_context():
and at some point in the end of the function, I store the maps into my DB.
I am having a hard time to conceptualize how the script will understand my app is running if I donāt āinformā him that it is working. Does the cron job even need to know that the app is working ?
Will the script understand that DB exists even if I just the whole function in a separate file ?