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

scheduling repeating tasks #121

Closed
jnlsn opened this issue Nov 18, 2015 · 4 comments
Closed

scheduling repeating tasks #121

jnlsn opened this issue Nov 18, 2015 · 4 comments

Comments

@jnlsn
Copy link

jnlsn commented Nov 18, 2015

I'm having difficulty scheduling a repeating task. I placed this in tasks.py, but it never gets called.

schedule(
    'core.tasks.process_emails',
    schedule_type='I',
    minutes=15
)

If I add the task from the Django admin, it gets called once, but then the repeating number decreases to -2 and it never runs again. What am I doing wrong here?

Apparently it is running again, I'm just impatient. I'd like to schedule it via code, though. Is there something wrong with the way I wrote it?

@Eagllus
Copy link
Collaborator

Eagllus commented Nov 19, 2015

When you have a django application running and you somewhere import the tasks.py
you will be able to see you schedules in the admin backend.
It will also display a field called Next Run.
If i'm not mistaking the -1 (or -2, -3, etc) shows the amount of runs that are behind.

Meaning if your cluster is turned off or you have a failing task, the count wil go up (negative way)
if your cluster comes back up or you task passes again the counter will go back to normal.
You can disable this catch_up from the settings.

@jnlsn
Copy link
Author

jnlsn commented Nov 19, 2015

Ah, okay. Is there a better place to put schedules than in tasks.py?

@Koed00
Copy link
Owner

Koed00 commented Nov 19, 2015

Unlike some other packages, Django-Q doesn't actually import anything at startup, but it will look for existing schedules in the database.
So you'll initially have to create that schedule somewhere in your workflow and afterwards it will just be part of your db. Since it's really just a database model instance of Schedule, you could easily check if this schedule exists or not and based on that create it or leave it as it is.

If you're just working on a single project I would just create the schedule in the admin or via the Django shell. However if you're planning on distributing your code, you should create the schedule in an initial setup step or, as described above, make sure you don't create it twice.

@Eagllus is right. When the repeating number is negative, the schedule will run forever but will still decrease that number the same way a number run would. I left it like that cause the negative number is a good indication of how often your schedule has been executed.

@jnlsn
Copy link
Author

jnlsn commented Nov 19, 2015

Cool, this makes sense to me now, thanks for clearing that up. Loving Django-Q, by the way. Amazing work!

@jnlsn jnlsn closed this as completed Nov 19, 2015
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

3 participants