R
Railway•2y ago
azura7200

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
Percy
Percy•2y ago
Project ID: b9621eca-5007-4afc-9f2b-6ea358fc79f9
azura7200
azura7200•2y ago
b9621eca-5007-4afc-9f2b-6ea358fc79f9
jackson
jackson•2y ago
why would you need to clear memory in django? sounds like there's a serious underlying problem
azura7200
azura7200•2y ago
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
jackson
jackson•2y ago
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
azura7200
azura7200•2y ago
Oh
azura7200
azura7200•2y ago
jackson
jackson•2y ago
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
azura7200
azura7200•2y ago
Oh got it
jackson
jackson•2y ago
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
azura7200
azura7200•2y ago
And i guess as long as my app is up, my execution hours will be charged
jackson
jackson•2y ago
yes
azura7200
azura7200•2y ago
By the way, just curious if there's actually a way to create cron job for a django based app
jackson
jackson•2y ago
use APScheduler can schedule functions on a cron schedule with proper logging, error handling, etc
azura7200
azura7200•2y ago
Brilliant! Will check this out. Thanks! 🙂
Want results from more Discord servers?
Add your server