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: slow django-q schedules saturate the queue and are run multiple times #5249

Closed
MichaelAkvo opened this issue Mar 14, 2023 · 0 comments
Closed

Comments

@MichaelAkvo
Copy link
Contributor

What were you doing?

Specifically result framework aggregations can take longer than a minute (which is the frequency of the schedule). That leads to:

  • parallel executions of the aggregation tasks
  • workers getting filled with the tasks
  • queue getting longer

What should've happened?

When the aggregation task is running, any renewed attempts to run it should just end.

My environment

No response

Additional context

https://github.com/Koed00/django-q/blob/master/django_q/cluster.py#L660

django-q doesn't check if a scheduled task is already queued or running before scheduling it

@MichaelAkvo MichaelAkvo added this to the New task management milestone Mar 14, 2023
MichaelAkvo added a commit that referenced this issue Mar 16, 2023
django-q doesn't support tracking of active task.
We therefore cannot make a simple query of "is this task already running".

All that is provided is a django signal before a task is executed with the task dictionary
 https://django-q.readthedocs.io/en/latest/signals.html#before-executing-a-task .
That's unfortunately not useful for our scenario as the edge case of an unexpected shutdown
 will block the unique task from executing in the future.
Were a timeout to be added and the task to still be running, the same task could be started again.

The chosen solution therefore, is a heartbeat thread.
MichaelAkvo added a commit that referenced this issue Mar 20, 2023
django-q doesn't support tracking of active task.
We therefore cannot make a simple query of "is this task already running".

All that is provided is a django signal before a task is executed with the task dictionary
 https://django-q.readthedocs.io/en/latest/signals.html#before-executing-a-task .
That's unfortunately not useful for our scenario as the edge case of an unexpected shutdown
 will block the unique task from executing in the future.
Were a timeout to be added and the task to still be running, the same task could be started again.

The chosen solution therefore, is a heartbeat thread.
MichaelAkvo added a commit that referenced this issue Mar 20, 2023
django-q doesn't support tracking of active task.
We therefore cannot make a simple query of "is this task already running".

All that is provided is a django signal before a task is executed with the task dictionary
 https://django-q.readthedocs.io/en/latest/signals.html#before-executing-a-task .
That's unfortunately not useful for our scenario as the edge case of an unexpected shutdown
 will block the unique task from executing in the future.
Were a timeout to be added and the task to still be running, the same task could be started again.

The chosen solution therefore, is a heartbeat thread.
zuhdil added a commit that referenced this issue Mar 22, 2023
…aturate-the-queue-and-are-run-multiple-times

[#5249] Add decorator to make django-q tasks unique
@zuhdil zuhdil closed this as completed May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

2 participants