Event Hub
zenml.event_hub
ZenML Event Hub module.
The Event Hub is responsible for receiving all Events and dispatching them to the relevant Subscribers/Triggers.
Modules
base_event_hub
Base class for event hub implementations.
Classes
BaseEventHub
Bases: ABC
Base class for event hub implementations.
The event hub is responsible for relaying events from event sources to action handlers. It functions similarly to a pub/sub system where event source handlers publish events and action handlers subscribe to them.
The event hub also serves to decouple event sources from action handlers, allowing them to be configured independently and their implementations to be unaware of each other.
zen_store: SqlZenStore
property
Returns the active zen store.
Returns:
Type | Description |
---|---|
SqlZenStore
|
The active zen store. |
Raises:
Type | Description |
---|---|
ValueError
|
If the active zen store is not a SQL zen store. |
activate_trigger(trigger: TriggerResponse) -> None
abstractmethod
Add a trigger to the event hub.
Configure the event hub to trigger an action when an event is received.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trigger
|
TriggerResponse
|
the trigger to activate. |
required |
Source code in src/zenml/event_hub/base_event_hub.py
163 164 165 166 167 168 169 170 171 |
|
deactivate_trigger(trigger: TriggerResponse) -> None
abstractmethod
Remove a trigger from the event hub.
Configure the event hub to stop triggering an action when an event is received.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trigger
|
TriggerResponse
|
the trigger to deactivate. |
required |
Source code in src/zenml/event_hub/base_event_hub.py
173 174 175 176 177 178 179 180 181 182 |
|
publish_event(event: BaseEvent, event_source: EventSourceResponse) -> None
abstractmethod
Publish an event to the event hub.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event
|
BaseEvent
|
The event. |
required |
event_source
|
EventSourceResponse
|
The event source that produced the event. |
required |
Source code in src/zenml/event_hub/base_event_hub.py
184 185 186 187 188 189 190 191 192 193 194 195 |
|
subscribe_action_handler(action_flavor: str, action_subtype: str, callback: ActionHandlerCallback) -> None
Subscribe an action handler to the event hub.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action_flavor
|
str
|
the flavor of the action to trigger. |
required |
action_subtype
|
str
|
the subtype of the action to trigger. |
required |
callback
|
ActionHandlerCallback
|
the action to trigger when the trigger is activated. |
required |
Source code in src/zenml/event_hub/base_event_hub.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
trigger_action(event: BaseEvent, event_source: EventSourceResponse, trigger: TriggerResponse, action_callback: ActionHandlerCallback) -> None
Trigger an action.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event
|
BaseEvent
|
The event. |
required |
event_source
|
EventSourceResponse
|
The event source that produced the event. |
required |
trigger
|
TriggerResponse
|
The trigger that was activated. |
required |
action_callback
|
ActionHandlerCallback
|
The action to trigger. |
required |
Source code in src/zenml/event_hub/base_event_hub.py
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 |
|
unsubscribe_action_handler(action_flavor: str, action_subtype: str) -> None
Unsubscribe an action handler from the event hub.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action_flavor
|
str
|
the flavor of the action to trigger. |
required |
action_subtype
|
str
|
the subtype of the action to trigger. |
required |
Source code in src/zenml/event_hub/base_event_hub.py
93 94 95 96 97 98 99 100 101 102 103 104 |
|
Functions
event_hub
Base class for all the Event Hub.
Classes
InternalEventHub
Bases: BaseEventHub
Internal in-server event hub implementation.
The internal in-server event hub uses the database as a source of truth for configured triggers and triggers actions by calling the action handlers directly.
activate_trigger(trigger: TriggerResponse) -> None
Add a trigger to the event hub.
Configure the event hub to trigger an action when an event is received.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trigger
|
TriggerResponse
|
the trigger to activate. |
required |
Source code in src/zenml/event_hub/event_hub.py
48 49 50 51 52 53 54 55 |
|
deactivate_trigger(trigger: TriggerResponse) -> None
Remove a trigger from the event hub.
Configure the event hub to stop triggering an action when an event is received.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trigger
|
TriggerResponse
|
the trigger to deactivate. |
required |
Source code in src/zenml/event_hub/event_hub.py
60 61 62 63 64 65 66 67 68 |
|
get_matching_active_triggers_for_event(event: BaseEvent, event_source: EventSourceResponse) -> List[TriggerResponse]
Get all triggers that match an incoming event.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event
|
BaseEvent
|
The inbound event. |
required |
event_source
|
EventSourceResponse
|
The event source which emitted the event. |
required |
Returns:
Type | Description |
---|---|
List[TriggerResponse]
|
The list of matching triggers. |
Source code in src/zenml/event_hub/event_hub.py
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 |
|
publish_event(event: BaseEvent, event_source: EventSourceResponse) -> None
Process an incoming event and trigger all configured actions.
This will first check for any subscribers/triggers for this event, then log the event for later reference and finally perform the configured action(s).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event
|
BaseEvent
|
The event. |
required |
event_source
|
EventSourceResponse
|
The event source that produced the event. |
required |
Source code in src/zenml/event_hub/event_hub.py
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 |
|