Add the ability to run parallel tasks #200
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request adds support for concurrent task processing in the database-backed worker by introducing multi-threading. The worker can now claim and process multiple tasks in parallel, controlled by a new
--max-workersoption. The changes also update the core query and locking logic to support batch task retrieval, and adjust related tests to reflect the new behavior.Concurrency and worker configuration:
--max-workerscommand-line option to the worker, allowing configuration of the maximum number of concurrent worker threads (default is 1, set byMAX_WORKERS) (django_tasks/backends/database/management/commands/db_worker.py,django_tasks/base.py). [1] [2] [3]max_workersparameter (django_tasks/backends/database/management/commands/db_worker.py). [1] [2] [3] [4]Task claiming and processing logic:
max_workerstasks concurrently using threads, instead of a single task at a time (django_tasks/backends/database/management/commands/db_worker.py). [1] [2]get_lockedmethod in the queryset to return a batch of locked tasks (as a queryset slice) instead of a single result, supporting batch locking (django_tasks/backends/database/models.py).Testing updates:
tests/tests/test_database_backend.py). [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]These changes collectively enable the worker to process multiple tasks in parallel, improving throughput and efficiency for database-backed task queues.