Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug? Hourly schedule_type runs in reverse #128

Closed
thinkwelltwd opened this issue Jan 5, 2016 · 1 comment
Closed

Bug? Hourly schedule_type runs in reverse #128

thinkwelltwd opened this issue Jan 5, 2016 · 1 comment

Comments

@thinkwelltwd
Copy link

I'm using Django Q to send emails on an hourly basis, and after the job runs, the "next_run" setting is changed to 2 hours prior to the run just complete, so the next minute the scheduler checks for new jobs if finds that same job, and reruns it, and again schedules it for 2 hours further back in history. Here's a printout taken over several job runs.

run 1. core.tasks.send_mail 2016-01-04 22:57:23.159561
run 2. core.tasks.send_mail 2016-01-04 18:57:23.159561
run 3. core.tasks.send_mail 2016-01-04 10:57:23.159561
run 4. core.tasks.send_mail 2016-01-03 02:57:23.159561
run 5. core.tasks.send_mail 2016-01-02 14:57:23.159561

And I suppose one gets the idea. If I switch the schedule_type to DAILY, then the next_run advances as expected.

Now, change schedule_type = "D":

run 1. core.tasks.send_mail D 2016-01-01 17:57:23.159561
run 2. core.tasks.send_mail D 2016-01-02 12:57:23.159561
run 3. core.tasks.send_mail D 2016-01-03 12:57:23.159561
run 4. core.tasks.send_mail D 2016-01-04 12:57:23.159561
run 5. core.tasks.send_mail D 2016-01-05 12:57:23.159561

And then by run 5 it's fully caught up and stops running every minute. Here's my code, which I'm calling in apps.py.

   class MyAppCore(AppConfig):
       name = 'core'
       verbose_name = 'MyApp Core'

    def ready(self):

        send = 'Cron: send_mail'
        if not Schedule.objects.filter(name=send).exists():
            Schedule.objects.create(
                name=send,
                func='core.tasks.send_mail',
                schedule_type=Schedule.HOURLY,
            )

The task is just a wrapper around the management command:

def send_mail():
    management.call_command('send_mail', **{'cron': 1})
@thinkwelltwd
Copy link
Author

Ok, egg on my face. I had the TimeZone problem in my settings file. Finally found the problem after a some careful placing of print statements showed that the next_run time changed between saving & extracting from the db. TADA. Gah!

Thanks for this excellent library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant