CeleryEventEmitter
class¶
Bases: EventEmitter
An event emitter subclass that utilizes the Celery distributed system to handle the execution of event emissions.
Notes:
- This class uses a Celery Queue instance to enqueue event emissions, which are subsequently executed by Celery workers. This approach provides a scalable and distributed method for handling the execution of event emissions.
Read more in the Pyventus docs for Celery Event Emitter.
Source code in pyventus/emitters/celery/celery_event_emitter.py
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
Classes¶
Queue
¶
A Celery event emitter queue used for enqueuing event emissions.
Source code in pyventus/emitters/celery/celery_event_emitter.py
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
Classes¶
Serializer
¶
An event emitter object serializer for Celery queues.
Source code in pyventus/emitters/celery/celery_event_emitter.py
Functions¶
dumps
staticmethod
¶dumps(obj: EventEmission) -> Any
Serializes the event emission object.
PARAMETER | DESCRIPTION |
---|---|
obj
|
The event emission object to be serialized.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
The serialized representation of the event emission object. |
Source code in pyventus/emitters/celery/celery_event_emitter.py
loads
staticmethod
¶loads(serialized_obj: Any) -> EventEmission
Deserializes the task payload back to the event emission object.
PARAMETER | DESCRIPTION |
---|---|
serialized_obj
|
The serialized object to be loaded.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
EventEmission
|
The deserialized event emission object. |
Source code in pyventus/emitters/celery/celery_event_emitter.py
Functions¶
__init__
¶
__init__(celery: Celery, name: str | None = None, secret: str | None = None, serializer: Type[Serializer] = Serializer) -> None
Initialize an instance of CeleryEventEmitter.Queue
.
PARAMETER | DESCRIPTION |
---|---|
celery
|
The Celery object used to enqueue and process event emissions.
TYPE:
|
name
|
The name of the queue where the event emission will be enqueued. Default is None (task_default_queue).
TYPE:
|
secret
|
The secret key used for message authentication and integrity validation. This key is used for hashing the event emission object and verifying its integrity.
TYPE:
|
serializer
|
The serializer class used for serializing and deserializing event emission objects.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
PyventusException
|
If the Celery object is None, or the secret key is not None and empty, or if the content type 'application/x-python-serialize' is not accepted. |
Source code in pyventus/emitters/celery/celery_event_emitter.py
enqueue
¶
enqueue(event_emission: EventEmission) -> None
Enqueues an event emission object for asynchronous processing in Celery.
This method takes an EventEmission
object and enqueues it for asynchronous
execution by Celery workers. If a secret key is provided during initialization,
the event emission object is first serialized, and its hash is calculated using
the secret key. This hash is used to verify the integrity of the event emission
object during execution.
PARAMETER | DESCRIPTION |
---|---|
event_emission
|
The event emission object to be enqueued for asynchronous execution.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None |
Source code in pyventus/emitters/celery/celery_event_emitter.py
Functions¶
emit
¶
Emits an event and triggers its associated event handlers.
Notes:
- When emitting
dataclass
objects orException
objects, they are automatically passed to the event handler as the first positional argument, even if you pass additional*args
or**kwargs
. - If there are event handlers subscribed to the global event
...
, also known asEllipsis
, they will also be triggered each time an event or exception is emitted.
PARAMETER | DESCRIPTION |
---|---|
event
|
The event to be emitted. It can be
TYPE:
|
args
|
Positional arguments to be passed to the event handlers.
TYPE:
|
kwargs
|
Keyword arguments to be passed to the event handlers.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None |
Source code in pyventus/emitters/event_emitter.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
__init__
¶
__init__(queue: Queue, event_linker: Type[EventLinker] = EventLinker, debug: bool | None = None) -> None
Initialize an instance of CeleryEventEmitter
.
PARAMETER | DESCRIPTION |
---|---|
queue
|
The queue used for enqueuing event emissions in the Celery event emitter.
TYPE:
|
event_linker
|
Specifies the type of event linker used to manage and access events along with their corresponding event handlers. Defaults to
TYPE:
|
debug
|
Specifies the debug mode for the logger. If
TYPE:
|