How to add cronjob in my django app?
As the title says, I want to add a cron job in my django project to clear memory every 5 minutes but i'm not able to do so. Can anyone please help?
15 Replies
Project ID:
b9621eca-5007-4afc-9f2b-6ea358fc79f9
b9621eca-5007-4afc-9f2b-6ea358fc79f9
why would you need to clear memory in django? sounds like there's a serious underlying problem
its just that i'm using free tier which gives 500 execution hours/month. Since the hours are calculated on the app's resource usage(which is primarily Memory in my case), i just want to minimize it so that it can run whole month.
currently its using around 380MB and the app is based on some computer vision models which i think loads the model in memory
i don't think that's how it works, execution hours are not based on memory
execution hours are based on how long a service is running
Oh
if you are using a lot of memory you will also hit the $5 limit potentially before the execution hour limit
yeah so the memory/cpu calculations count towards your dollar amount limit and the actual time you have a project running counts towards your execution hours limit
whichever one you hit first will bottleneck your plan
Oh got it
even if it didn't you don't really want to continuously unload and load a model from memory, that would be extremely slow for the end user
And i guess as long as my app is up, my execution hours will be charged
yes
By the way, just curious if there's actually a way to create cron job for a django based app
use APScheduler
can schedule functions on a cron schedule with proper logging, error handling, etc
Brilliant! Will check this out. Thanks! 🙂