celery-dispatcher
An extension for celery to dispatch large amount of subtasks within a main task, and process the results separately.
Installation
pip install celery-dispatcher
Usage
NOTICE:
celery-dispatcheruse tls to store running info, so the pool implementation using coroutines(like eventlet/gevent) can not be used
Firstly, yield subtask and its parameters in tuple from the main task by following order:
task: signatureargs: tupple/listkwargs: dictoptions: dict
Then register the result handler for each subtask using signal:
from celery import shared_task
from celery_dispatcher import dispatch
from celery_dispatcher.signals import subtask_success
@shared_task
def sqrt(i):
return i * i
@dispatch
@shared_task
def calc():
for i in range(10):
yield sqrt, (i,)
@subtask_success.connect(sender=calc)
def handle_result(root_id, task_id, retval, **kwargs):
print(retval)
Or register in the decorator directly:
from celery import shared_task
from celery_dispatcher import dispatch
@shared_task
def sqrt(i):
return i * i
def handle_result(root_id, task_id, retval, **kwargs):
print(retval)
@dispatch(receiver=handle_result)
@shared_task
def calc():
for i in range(10):
yield sqrt, (i,)
If you want to revoke all subtasks, call revoke with specific signal:
import signal
from celery import shared_task
from celery_dispatcher import dispatch
@shared_task
def subtask(i):
...
@dispatch
@shared_task
def maintask():
for i in range(10):
yield subtask, (i,)
result = maintask.delay()
result.revoke(terminate=True, signal=signal.SIGUSR1)
Options
The dispatch accepts the following parameters:
options: dictreceiver: callablebackend: strauto_ignore: bool
General settings
dispatcher_result_backend
Default: No result backend enabled by default.
The backend used to store subtask info. Can be one of the following:
- redis: Use Redis to store the results. See Redis backend settings.
dispatcher_batch_size
Default: 100
The batch size of subtask dispatching, or the result retrieving.
dispatcher_poll_size
Default: 100
The queue size of subtasks in result retrieving. celery-dispatcher put the unfinished subtasks into a queue, polling it continuously for completion of subtasks.
dispatcher_poll_timeout
Default: 10
The default timeout for polling subtasks.
dispatcher_subtask_timeout
Default: 3600
The default timeout in seconds before celery-dispatcher gives up retrieving the result of each subtask.
dispatcher_failure_on_subtask_timeout
Default: False
Whether raise exception when subtask timeout.
dispatcher_failure_on_subtask_exception
Default: False
Whether raise exception from subtask.
dispatcher_progress_update_frequency
Default: 1
The number of steps to record. celery-dispatcher only actually store the updated progress in the background at most every N steps.
Metadata
Release files for celery-dispatcher 1.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| celery-dispatcher-1.1.3.tar.gz | 12.3 kB | Without provenance | Details for celery-dispatcher-1.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| celery_dispatcher-1.1.3-py3-none-any.whl | Python 3 | none | any | Details for celery_dispatcher-1.1.3-py3-none-any.whl |
Total release size: 26.6 kB
Release files / celery-dispatcher-1.1.3.tar.gz
| Download URL | celery-dispatcher-1.1.3.tar.gz |
|---|---|
| Size | 12.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
906583aa51f63ac7a1d9c1bf749004b98743cd4312c52dcd8cb153be8ab9d533
|
|
BLAKE2b-256 checksum How to use checksums |
e3149252676f3d46dd9eae29f639eafd00a14c20f2517a86a36bdaa725a0e6a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / celery_dispatcher-1.1.3-py3-none-any.whl
| Download URL | celery_dispatcher-1.1.3-py3-none-any.whl |
|---|---|
| Size | 14.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
21bd7fdf3d76e27fab758344b38f07d5aac6babe9731b2b6daabc1cba401a064
|
|
BLAKE2b-256 checksum How to use checksums |
6a538023a4e743baff17fc18c03aaade45efcb7a7d52a7f33514e9ac9c347e68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for celery-dispatcher 1.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.