EventPublisher¶
Source code: event_collector.publisher.py
This module implements the CollectorEvent and EventPublisher.
An EventPublisher sends CollectorEvents to the collector queue. The publisher is automatically created when the collector queue is initialized.
Constants & Data Structures¶
- event_collector.publisher.DEFAULT_PRIORITY: int = 1000¶
Default priority level for a priority queue.
Event Publisher & CollectorEvent¶
- class event_collector.publisher.EventPublisher(event_queue: Queue, *, queue_type: QueueType = QueueType.FIFO, default_priority: int = 1000)¶
The
EventPublisheris used to send events to the event queue.An
EventPublisheris automatically created by theCollectorQueueat initialization so you do not need to create this manually. TheCollectorQueuewill also set thequeue_typebased on its input parameters.When the
CollectorQueueis running, you can access theEventPublisherusing theCollectorQueue.get_publishermethod. To send event payloads to the queue, use theEventPublisher.sendmethod.- async send(data: Payload) CollectorEvent¶
The
sendmethod is used to put an input event payload onto the event queue. The method returns aCollectorEventinstance which can be used to await the result.Example:
... publisher = collector_queue.get_publisher() payload = Payload({"data": "some data"}) event = await publisher.send(payload) # event.wait() will block until processing finishes result = await event.wait()
If result is not needed – in a “fire-and-forget” use case – just use
sendand ignore the return value:payload = Payload({"data": "some data"}) await publisher.send(payload)
If using a priority queue, include a priority value (int) in the
Payload:payload = Payload({"data": "some data"}, priority=1) await publisher.send(payload)
Python’s
asyncio.PriorityQueueuses a min-heap and is sorted by lowest first (lower value has higher priority).
- async wait() None¶
The
waitmethod waits for all events to be processed and will block until all events sent the collector queue are processed.
- class event_collector.publisher.CollectorEvent(event_id: int, payload: Payload, *, priority: int = 1000)¶
A
CollectorEventis a container for an event payload and the event’s result after processing. It’s created automatically by theEventPublisherfor each event payload sent to the collector queue.- get_result() ResultList | None¶
- Returns:
a ResultList or None if result is not yet available.
- async wait() ResultList¶
Return the ResultList if the event is finished, or else create a
Futureobject and await its completion. This will block until theFutureis marked as finished by a consumer setting its result.
- service_time() MonotonicTime¶
Return service_time (in nanoseconds) If event is not yet finished, return 0.
- wait_time() MonotonicTime¶
Return total processing time (in nanoseconds) from creation to stop. If event is not yet finished, return 0.