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

runcrons is once-and-for-all? #21

Closed hunanboy closed 11 years ago

hunanboy commented 11 years ago

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 every time I run runcrons command (instead of send one email per minute). That defeats the purpose of cron... Am I missing something?

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)
dfryta commented 11 years ago

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.

hunanboy commented 11 years ago

Thanks I notice you have answered my question on SO as well:) Let's move over there. It might benefit more people. And may I suggest you add this answer to project wiki? It clarify things for newbies like me. I once thought the purpose of your app is to by-pass crontab entirely.

GESTIFANOS commented 10 years ago

This is like creating cron job on top of another cron job.

DanielStevenLewis commented 9 years ago

I also experienced this issue until finding this ticket. Documentation could use further clarification. "everytime you run the management command python manage.py runcrons all the crons will run if required." indicates to me that manage.py runcrons starts a recurring cron job

craiglabenz commented 9 years ago

Link to the SO question, for posterity?

shivamsinghal212 commented 6 years ago

I don't understand the point of setting schedule in django-cron, If we are setting it using the windows task scheduler.

craiglabenz commented 6 years ago

@shivamsinghal212 The idea is that your window task scheduler will invoke python manage.py runcrons very regularly -- say, every minute, or every 5 minutes. django-cron then internally maintains the schedule of your jobs, launching each as necessary. This allows you to easily keep said schedules inside your application code and thus inside version control.