Tivix / django-cron

Write cron business logic as a Python class and let this app do the rest! It enables Django projects to schedule cron tasks, tracks their success / failures, manages contention (via a cache) etc. Basically takes care of all the boring work for you :-)
www.tivix.com
MIT License
900 stars 193 forks source link

Cronjob RUN_EVERY_MINS=1 not actually running every minute #112

Closed jeremych1000 closed 2 years ago

jeremych1000 commented 7 years ago

Not sure why the cronjob isn't being run every minute :/ sometimes it does, sometimes it doesn't.

I saw https://github.com/Tivix/django-cron/issues/91#issuecomment-268465804 but is there any solution to this?

Any other information I can provide? Django running on a raspberry pi, client running ubuntu 16.

Django console

2017-03-12 01:13:02,042 [INFO] django.server: "POST /bootstrap/keep_alive/ HTTP/1.1" 200 20 2017-03-12 01:15:02,181 [INFO] django.server: "POST /bootstrap/keep_alive/ HTTP/1.1" 200 20 2017-03-12 01:17:02,458 [INFO] django.server: "POST /bootstrap/keep_alive/ HTTP/1.1" 200 20 2017-03-12 01:19:01,640 [INFO] django.server: "POST /bootstrap/keep_alive/ HTTP/1.1" 200 20 2017-03-12 01:20:02,290 [INFO] django.server: "POST /bootstrap/keep_alive/ HTTP/1.1" 200 20

Client cronjob log using grep CRON /var/log/syslog

Mar 11 17:13:01 ubuntu CRON[5962]: (jeremych) CMD (cd ~/ee4-FYP/software/peer; python3 manage.py runcrons >> ~/cron.log) Mar 11 17:13:02 ubuntu CRON[5961]: (CRON) info (No MTA installed, discarding output) Mar 11 17:14:01 ubuntu CRON[5998]: (jeremych) CMD (cd ~/ee4-FYP/software/peer; python3 manage.py runcrons >> ~/cron.log) Mar 11 17:15:01 ubuntu CRON[6004]: (jeremych) CMD (cd ~/ee4-FYP/software/peer; python3 manage.py runcrons >> ~/cron.log) Mar 11 17:16:01 ubuntu CRON[6010]: (jeremych) CMD (cd ~/ee4-FYP/software/peer; python3 manage.py runcrons >> ~/cron.log) Mar 11 17:17:01 ubuntu CRON[6032]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly) Mar 11 17:17:01 ubuntu CRON[6034]: (jeremych) CMD (cd ~/ee4-FYP/software/peer; python3 manage.py runcrons >> ~/cron.log) Mar 11 17:18:01 ubuntu CRON[6044]: (jeremych) CMD (cd ~/ee4-FYP/software/peer; python3 manage.py runcrons >> ~/cron.log) Mar 11 17:19:01 ubuntu CRON[6062]: (jeremych) CMD (cd ~/ee4-FYP/software/peer; python3 manage.py runcrons >> ~/cron.log) Mar 11 17:20:01 ubuntu CRON[6069]: (jeremych) CMD (cd ~/ee4-FYP/software/peer; python3 manage.py runcrons >> ~/cron.log)

crontab -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* * * * * cd ~/ee4-FYP/software/peer; python3 manage.py runcrons >> ~/cron.log

django_cron code

class Keep_Alive(CronJobBase):
    RUN_EVERY_MINS = 1
    schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
    code = 'peer.keep_alive'

    def do(self):
        <my code, POST request to /keep_alive/>
Morvarid commented 7 years ago

I'm experiencing the same issue.

FrankMeyer commented 7 years ago

Maybe it is caused by previous other CronJobBase classes still running. The actual command is not calling the different CronJobBase classes in parallel. They are executed iteratively. See PR #88 Maybe that helps

JedrzejMaluszczak commented 2 years ago

Use manage.py cronloop -s where s is sleep interval in seconds. 300s by default