Hey guys,
I really appreciated all the help in deciding which python framework to use for my app. I ended up going with django and it's slowly coming together. So thank you š.
I've got another question now -> I already have a python script that loops continuously and runs every 24 hours that was built prior to the web app. I'm wondering if I can integrate it on the django platform and have it run on a server (when I deploy) like it currently runs on my PC. (given all the proper dependencies of course).
Again, I'm still a kid at this stuff so I apologise if this makes no sense.
You can create a Django Management Command that you run from a cronjob.
On top of that itās also worth to mention that Django works very well with Celery. You can use Celery to execute asynchronous tasks but also to schedule tasks to be executed on a crontab schedule (but itās using Celery workers instead of a Linux cronjob under the hood).
+1 for Celery, or if you don't have a lot of tasks and they aren't very complex, you could also use: https://github.com/arteria/django-background-tasks
I've used them both and they did a good job, it depends a lot on your use case.
Hey Mike, Iām trying to use the Django-background-tasks tot run a script every 24 hrs. But Iām not sure Iām doing it right... do you know of a good tutorial?
I've got my sript working just by reading their documentation: https://django-background-tasks.readthedocs.io/en/latest/
You just have to use the decoration: @background(schedule=30), this will be run in 30 minutes.
Of course, when you call such a task, you can change the default schedule like this: function_name(args, schedule={date and time when the task shuld run})
Let me know if you have other questions.
Awesome, Iāll probably hit you up again when I deploy the appš
Okay, thatās super helpful! Iāll have to do so research on Celery. I appreciate the help š
Hey, congrats on moving the script to cloud.
Yeah, CRONS are absolutely fine and easy to start. I have been using Django with crons for last 7 years.
Few tips:
Add
MAILTO="[email protected]"
in crontab to mail the results output of your script. I try to ensure that all my cron scripts have no verbosity unless there is error or warning.You can add recurring cron jobs using
*/n * * * *
syntax. Example*/5 * * * *
will run every 5 minutes.Other tips: https://www.endpoint.com/blog/2008/12/08/best-practices-for-cron
Syntax generator: https://crontab.guru
Use Cronitor or DeadManSnitch for monitoring very critical cron jobs. Emails for errors have worked fine for me.
Thank you for the help man! I really appreciate that š have you ever used cronhub?
Haven't tried cronhub but it looks good.