Cronjob is run every time runcrons is called
See original GitHub issueWe just noticed some strange behaviour on our staging server after updating from django-cron 0.4.6 to 0.5.0. One of our jobs looks like this:
class AnalyticsReportJob(CronJobBase):
RUN_EVERY_MINS = 60 * 24
schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
code = 'analytics.report'
def do(self):
do_stuff()
It’s supposed to report on gathered analytics data once a day, basically just collecting and sending out some emails. Real cron is calling runcrons
every minute. After experiencing some heavy load and unexpected behaviour, we could confirm that do_stuff()
is actually executed every minute, leading to several critical issues including zombie processes.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Django cron runs multiple time, but it shouldn't - Stack Overflow
Your cronjob is running every minute. See here for an explanation. Crons are broken into: minute hour day(month) month day(week).
Read more >Cron Jobs: A Comprehensive Guide - SitePoint
Cron Job: a cron job is a scheduled job. The daemon runs the job when it's due. Webcron: a time-based job scheduler that...
Read more >Cron - Gentoo Wiki
Cron is a daemon that runs scheduled tasks based on input from the command crontab. It accomplishes this task by waking up every...
Read more >django-cron Documentation - Read the Docs
Now everytime you run the management command python manage.py runcrons all ... the management command can be called from the Unix crontab as....
Read more >Installation — django-cron 0.5.1 documentation
Now everytime you run the management command python manage.py runcrons all the crons ... command can be called from the Unix crontab as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, i have the same issue but the provided fix didn’t solve it.
By looking at the code it seems that the CronJobLog record doesn’t get inserted to the database until the job finishes. That way the query in CronJobManager.should_run_now wont find the job that is already running and start the job again before the first one finishes.
I’ve made a quick fix to CronJobManager.run by adding:
self.make_log('Job Running!!', success=True)
Just before the line:self.msg = self.cron_job.do()
And it works!! 😃
I don’t have access to the environment in question anymore, but we did use
USE_TZ
, and I’m pretty sure the servers were in Ireland (AWS).