question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cronjob is run every time runcrons is called

See original GitHub issue

We 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:closed
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
pvojnovcommented, Sep 14, 2017

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!! 😃

0reactions
sulamicommented, Jan 18, 2017

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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found