Package: django-serverless-cron
django-serverless-cron is a Django app with a simpler approach running cron jobs.
This is done through exposing a HTTP endpoint to invoke the jobs that allows you to run any task without having to manage always-on infrastructure.There is also an option to run jobs via management commands and the Django admin.Why?This is essentially a replacement/supplement for a traditional OS ‘cron’ or ‘job scheduler’ system:Serverless cron jobs no-longer a pain.Schedule jobs to run at a frequency that is less than 1 min. (crontab is limited to 1 min)The machine running crontab is no longer a single point of failure.The problem with the above systems is that they are often configured at the operating system level, which means their configuration is probably not easily ‘portable’ and ‘debug-able’ (if you are developing on Windows, the scheduler works differently from Linux or Unix). Also can not easily be integrated into a development environment.Manually triggered cron jobs. Eg: via the Django Admin.Alternative to cron services that aren’t always available on free (and sometimes paid) web hosting services.Easier access to cron job execution logs and monitoring execution failures.No need to learn crontab. Think of it as a friendlier alternative to traditional cron jobs. Simple cron job creation. No need for cron syntax, no guessing on job frequency. Easy controls.DocumentationDocumentation is graciously hosted athttps://django-serverless-cron.readthedocs.io.ContributionsFeel free to make pull requests and submit issues/requests.
Find more detailed instructions under thecontributingsection.Alternatively, you can leave a star on the repo to show your support. 🙂QuickstartInstallationInstall Django Serverless Cron:pip install django-serverless-cronSettingsAdd it to yourINSTALLED_APPS:INSTALLED_APPS=(# ...'django_serverless_cron'# ...)Add jobs to your settings file:SERVERLESS_CRONJOBS=[# (#   '1_hours',                       # frequency (seconds, minutes, hours, days, weeks) -> in this case, every one hour#   'mail.jobs.send_mail_function',  # path to task/function functions -> in this case, send_mail_function()#   {'kwarg1': 'foo'}                # kwargs passed to the function# ),('1_days','your_app.services.your_job_function',{'kwarg1':'foo','kwarg2':'bar'}),('1_hours','mail.jobs.send_mail_function',{"is_bulk":True}),]URL patternsAdd the jobs to your URL patterns:fromdjango_serverless_cronimporturlsasdjango_serverless_cron_urlsurlpatterns=[# ...url(r'^',include(django_serverless_cron_urls))#...]Migratepythonmanage.pymigrateRunning JobsIn DevelopmentRunning Jobs through HTTP requestsCall the/runpath to run all jobs:Example:curlhttp://localhost:8000/runorimportrequestsx=requests.get('http://localhost:8000/run')Running Jobs through the management commandThis will run the jobs every 30 seconds:pythonmanage.pyserverless_cron_runYou can alternatively add the–single_run=’True’option to run the jobs just once.In ProductionSimilar to in development, we can call the/runpath via fully managed services which are usually ridiculously cheap. Examples:https://cloud.google.com/scheduler-> Great feature set, easy to use, reasonable free tier & very cheap.https://aws.amazon.com/eventbridgehttps://azure.microsoft.com/en-gb/services/logic-appsformerlyhttps://docs.microsoft.com/en-us/azure/scheduler/scheduler-introhttps://cron-job.org/en/-> Absolutely free and open-source:https://github.com/pschlan/cron-job.orghttps://www.easycron.comhttps://cronhub.iohttps://cronless.com-> Has 30 Second Cron Jobshttps://github.com/features/actions;https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onschedule-> eg making a HTTP request usingcurlin a stephttps://www.cronjob.dehttps://zeplo.iohttps://catalyst.zoho.com/help/cron.htmlhttps://www.cronjobservices.comRelated mediaFor more learning check out:https://dev.to/googlecloud/when-you-re-not-around-trigger-cloud-run-on-a-schedule-53p4|https://youtu.be/XIwbIimM49Yhttps://aws.amazon.com/blogs/compute/using-api-destinations-with-amazon-eventbridge/https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/RunLambdaSchedule.htmlhttps://www.ibm.com/cloud/blog/how-to-schedule-rest-api-calls-on-ibm-cloudhttps://vercel.com/docs/concepts/solutions/cron-jobshttps://www.dailyhostnews.com/google-cloud-launches-fully-managed-cron-job-scheduler-for-enterprisesCloud Scheduler from Fireshiphttps://www.youtube.com/watch?v=WUPEUjvSBW8CreditsTools used in rendering this package:Cookiecuttercookiecutter-djangopackageHistory0.1.3 (2022-01-02)fix bug in running the management commandwraprun_all_jobs()in a class0.1.2 (2022-01-01)Fix typo in the docs0.1.1 (2022-01-01)Birth: First release on PyPI.Has the ability to:Run jobs via the/runpathRun jobs via the management commandserverless_cron_run.py