djangocrondjango-cron

How to use Tivix django-cron app


I got exact same problem described in this post, but the answer doesn't help at all. In short, I am using Tivix django-cron, the cron job is not running at regular basis.

To illustrate the problem, the following cron job class is intended to send email every min once running runcrons command. But in fact, it only sends out one email and no more. That defeats the purpose of cron... What am I missing?

class TestCron(CronJobBase):
    schedule = Schedule(run_every_mins=1)
    code = 'test_cron_philip'

    def do(self):
        send_mail('cron test', 'body is test body', 'coach_zhong@163.com',
                  ['admin@dessert.webfactional.com'],fail_silently=False)

Solution

  • Yes, you miss something ("runcrons" is not background deamon). From documentation:

    "Now everytime you run the management command python manage.py runcrons all the crons will run if required. Depending on the application the management command can be called from the Unix crontab as often as required. Every 5 minutes usually works for most of my applications."

    That means you have to put "runcrons" command in your crontab.

    Example:

    You have some CronJob that do something every 30 min.

    To get this running you must edit you crontab (linux, mac) or task scheduler (windows) to run "python manage.py runcrons" for every, let say 1 min.

    If you get this running, your CronJob will be pinged every 1 min and run if necessary (every 30 min or whatever value you have set).

    Hope this helps.