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

Periodic tasks add only if #320

Closed
fonzmeister opened this issue Sep 11, 2018 · 3 comments
Closed

Periodic tasks add only if #320

fonzmeister opened this issue Sep 11, 2018 · 3 comments

Comments

@fonzmeister
Copy link

I use django-q for some background tasks. The tasks looks like this in pseudocode

def task(param)
  if param:
    do_something() #runs instantly
  if not param:
    do_something_else() #takes a while to run
    time.sleep(3600)

If I run the task every 5 minutes and param == False for a few times in a row I will create a lot of tasks and my queue will overflow. Is there a way that only a new task is created if there is no task running, taking into consideration the timeout?

@kbuilds
Copy link

kbuilds commented Sep 11, 2018

Would it be possible to have this task schedule a second task which exectes the long-running code?

That way, the task that is scheduled to run every 5 minutes can check the current queue, and decide whether to schedule another long-running task. Either way, it will finish relatively quickly.

@fonzmeister
Copy link
Author

That will probably work. Will give it a go. Thanks!

Still think it might be nice feature though, if it is not too much work.
Nice job on the project so far btw, I really like it

@fonzmeister
Copy link
Author

fonzmeister commented Sep 17, 2018

~~I cannot get this to work. I need to pass an object into the function, which is causing me problems, since it can not be pickled

I rewrote the project a bit so this will work. But I cannot find how to acces the queue in te manual. Can you give me a little tip whith this?~~

Found it, you can acces the queue with from django_q.models import OrmQ and then do queries like you would do with a regular model in django

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

2 participants