CeleryProcessingService
class¶
Bases: ProcessingService
A processing service that utilizes the Celery
framework to handle the execution of calls.
Notes:
-
This service leverages the
Celery
framework to enqueue the provided callbacks into a distributed task system, which is monitored by multiple workers. Once enqueued, these callbacks are eligible for retrieval and processing by available workers, enabling a scalable and distributed approach to handling calls asynchronously. -
Synchronous callbacks are executed in a blocking manner inside the worker, while asynchronous callbacks are processed within a new asyncio event loop using the
asyncio.run()
function.
Source code in pyventus/core/processing/celery/celery_processing_service.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
Attributes¶
CELERY_TASK_NAME
class-attribute
instance-attribute
¶
The name of the task in Celery.
Classes¶
CeleryPayload
dataclass
¶
Functions¶
register
classmethod
¶
Register the service's task globally in Celery
.
Notes:
-
This method should be invoked in the
Celery
worker script to ensure that the task is accessible to both the client and the worker. If this method is not called, aKeyError
will be raised when attempting to submit a new callback. -
This method uses the
shared_task
functionality from theCelery
framework to register the service's task, making it available independently of theCelery
instance used. -
The registered task is a
Celery
task that will be used to process the execution of callbacks.
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
Source code in pyventus/core/processing/celery/celery_processing_service.py
__init__
¶
Initialize an instance of CeleryProcessingService
.
PARAMETER | DESCRIPTION |
---|---|
celery
|
The Celery object used to enqueue and process callbacks.
TYPE:
|
queue
|
The name of the queue where callbacks will be enqueued. Defaults to None, which uses the
TYPE:
|
RAISES | DESCRIPTION |
---|---|
PyventusException
|
If the Celery instance is invalid or if the queue name is set but empty. |