事件¶
进程内事件管道:通道隔离、优先级排序、重试策略与死信记录。
zoo_framework.event.event_channel.EventChannel ¶
Event channel.
The queue and the reactor manager are both instance-level:
EventChannel is created and cached by name in EventChannelRegister;
the singleton belongs on the registrar (the name -> channel map), not on
the queue each channel instance holds inside itself. Both used to be
class attributes, making all channels share one queue.
源代码位于: zoo_framework/event/event_channel.py
9 10 11 12 13 14 15 16 17 18 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 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 | |
wait_ready ¶
消费者挂起等待本通道有事件(推模型启用时).
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
timeout
|
float
|
兜底超时(秒);超时后调用方恢复扫描(防生产者漏 notify) |
必需 |
返回:
| 类型 | 描述 |
|---|---|
bool
|
True 表示本次调用观察到队列非空(进入时已非空,或被 notify 唤醒); |
bool
|
False 表示等满兜底超时后仍空,或推模型未启用 |
源代码位于: zoo_framework/event/event_channel.py
notify_ready ¶
get_reactors ¶
get_channel_name ¶
set_public ¶
is_public ¶
size ¶
pop_value ¶
get_top ¶
push_event ¶
Push an event into the event queue.
Push model: notify suspended consumers after a successful enqueue; a failed enqueue does not notify (the queue did not change).
源代码位于: zoo_framework/event/event_channel.py
dispatch ¶
Push an event into the event queue (same push-model semantics as push_event).
register_reactor ¶
Register an event reactor.
Also records the channels the reactor listens to - only the channel
initiating the registration knows the channel's name. Previously only
the topic binding was done without the channel registration, so the
channel constraint declared by @event(channel=...) did not apply at
all on the dispatch hot path: the channel manager found no
registration and let everything through on the default channel.
源代码位于: zoo_framework/event/event_channel.py
refresh_event ¶
Refresh an event.
push_dead_letter ¶
Record an event that cannot be delivered.
An event taken from the queue MUST have a settled destination: delivered, requeued, or recorded here. "Popped and neither delivered nor requeued" MUST NOT happen - that is exactly how events get lost silently.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
event
|
EventNode
|
the event that could not be delivered |
必需 |
reason
|
str
|
the reason it could not be delivered, for troubleshooting |
''
|
源代码位于: zoo_framework/event/event_channel.py
zoo_framework.event.event_channel_register.EventChannelRegister ¶
The event channel registrar.
Registry ownership (absorb-debt-carriers / #50): _channel_map is state
of the process-level instance (this class is registered into the
framework container via process_scoped), no longer a class attribute;
the previously self-declared [known debt] is lifted by the absorption.
The historical dead attributes _single / _instance (legacy singleton
markers with zero reads or writes repo-wide) are removed with it.
源代码位于: zoo_framework/event/event_channel_register.py
zoo_framework.event.event_register.EventRegister ¶
The event registrar.
源代码位于: zoo_framework/event/event_register.py
反应器¶
zoo_framework.reactor.event_reactor.EventReactor ¶
源代码位于: zoo_framework/reactor/event_reactor.py
8 9 10 11 12 13 14 15 16 17 18 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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
set_retry_strategy ¶
get_priority ¶
The combined priority.
Segmented encoding: the system priority takes the high bits (shifted
left by 8), the user priority the low bits; together they decide
ordering. This MUST be bitwise OR, not bitwise AND - & would zero
the low segment under the high segment, degrading every reactor's
combined priority to the same value.
源代码位于: zoo_framework/reactor/event_reactor.py
set_event_timeout ¶
Set the join-timeout exemption line (issue #232).
A non-positive value means undeclared: the reactor follows the global
event:timeout (EVENT_JOIN_TIMEOUT). A positive value declares the
reactor legitimately slow and exempts it from the "results were not
collected" warning within that bound.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
timeout
|
float | None
|
the effective timeout in seconds; None or <= 0 means follow the global default |
必需 |
源代码位于: zoo_framework/reactor/event_reactor.py
execute ¶
Execute the event.
源代码位于: zoo_framework/reactor/event_reactor.py
zoo_framework.reactor.event_reactor_manager.EventReactorManager ¶
Event reactor manager.
P1 task: event channel isolation.
Registry ownership (change absorb-debt-carriers / #50): reactor_map is
the state of the process-level instance (this class is registered in
the framework container via process_scoped), no longer a class
attribute - the INSTANCE_GUARANTEED thread-safety declaration is thereby
faithful to the implementation; a container reset resets it fully.
源代码位于: zoo_framework/reactor/event_reactor_manager.py
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 | |
dispatch
classmethod
¶
dispatch(topic: str, content: Any, reactor_name: str | None = None, channel: str = ChannelType.DEFAULT.value)
Dispatch an event.
Executes each reactor under the topic that passes the channel validation. An exception raised by one reactor does not block the others; returns silently when no reactor matches the topic.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
topic
|
str
|
the event topic |
必需 |
content
|
Any
|
the event content |
必需 |
reactor_name
|
str | None
|
the reactor name; None means no filtering. The
legacy sentinel value "default" is also treated as no
filtering - it comes from this method's old signature and
conflicts with |
None
|
channel
|
str
|
the channel name |
DEFAULT.value
|
源代码位于: zoo_framework/reactor/event_reactor_manager.py
get_reactor
classmethod
¶
get_reactor(topic: str, reactor_names: list[str] | None = None, channel: str | None = None) -> list[Any]
Get the event reactors.
P1 task: filter event reactors by channel.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
topic
|
str
|
the event topic |
必需 |
reactor_names
|
list[str] | None
|
the reactor name list |
None
|
channel
|
str | None
|
the channel name (added in P1) |
None
|
返回:
| 类型 | 描述 |
|---|---|
list[Any]
|
The reactor list |
源代码位于: zoo_framework/reactor/event_reactor_manager.py
register_reactor_channels
classmethod
¶
Register the channels a reactor listens to.
P1 task: channel isolation configuration.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
reactor_name
|
str
|
the reactor name |
必需 |
channels
|
list[str]
|
the list of listened channels |
必需 |
源代码位于: zoo_framework/reactor/event_reactor_manager.py
get_reactor_name_list
classmethod
¶
bind_topic_reactor
classmethod
¶
Register an event reactor.
Idempotent: when the same reactor object is registered for the same topic repeatedly, the reactor set under the topic stays unchanged - neither appended again nor renamed. The legacy implementation renamed and appended in that case, so each scheduler construction piled one more record under the topic and grew without bound within the process.
This method may be overridden to implement different event registration styles, e.g. adding a retry mechanism.
源代码位于: zoo_framework/reactor/event_reactor_manager.py
dispatch_by_channel
classmethod
¶
Dispatch an event by channel.
P1 task: broadcast events by channel.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
topic
|
str
|
the event topic |
必需 |
content
|
Any
|
the event content |
必需 |
channel
|
str
|
the target channel |
DEFAULT.value
|
源代码位于: zoo_framework/reactor/event_reactor_manager.py
zoo_framework.reactor.waiter_result_reactor.WaiterResultReactor ¶
Bases: EventReactor
The Waiter result reactor.
Subscribes to the unified result topic
(WaiterConstant.WORKER_RESULT_TOPIC). The reactor itself does no
business processing; it has two duties:
- make that topic a first-class citizen on the event pipeline -
bind_topic_reactorneeds a registered target - provide a filter-by-worker-name entry point: set
worker_namesto receive results from only the named Workers
worker_names holds registration names (the suffix-free identity),
so worker_names=['ok'] receives the results of Worker ok whatever
its instance ordinal is (ok_1, ok_2, ...). Matching is exact, not
prefix-based: ok MUST NOT match a Worker named ok2. The
ordinal-bearing instance name may also be listed explicitly, for callers
that already know it. An empty/None worker_names means receive from
all Workers.
Received results are handed over via the optional on_result callback;
the reactor itself never accumulates results, avoiding unbounded growth
over long runs.
源代码位于: zoo_framework/reactor/waiter_result_reactor.py
accepts ¶
Decide whether this result should be accepted by the reactor.
The filter is declared with the Worker's registration name
(worker_names=['ok']), while the result carries the instance name
including the ordinal (ok_1). Matching therefore compares the
ordinal-free identity rather than the raw instance name; comparing the
two directly never matched, which silently filtered everything
out (issue #229).
A result is accepted when any of its identities is in the filter:
registry_name (the suffix-free field), the trailing-ordinal-stripped
form of worker_name (covers results built outside
BaseWorker.run), or worker_name itself (the exact instance
name, kept for backward compatibility). Matching stays exact - this is
a real filter, not a prefix match.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
result
|
Any
|
the Worker execution result |
必需 |
返回:
| 类型 | 描述 |
|---|---|
bool
|
whether to accept |
源代码位于: zoo_framework/reactor/waiter_result_reactor.py
zoo_framework.reactor.event_priorities ¶
EventPriorities ¶
Bases: Enum
Event priorities for the reactor.
源代码位于: zoo_framework/reactor/event_priorities.py
zoo_framework.reactor.event_retry_strategy.EventRetryStrategy ¶
队列¶
zoo_framework.fifo.base_fifo.BaseFIFO ¶
Bases: Generic[_T]
FIFO base class.
源代码位于: zoo_framework/fifo/base_fifo.py
zoo_framework.fifo.event_fifo.EventFIFO ¶
Bases: BaseFIFO[EventNode]
The event queue.
源代码位于: zoo_framework/fifo/event_fifo.py
push_value ¶
Push an event into the event queue.
源代码位于: zoo_framework/fifo/event_fifo.py
dispatch ¶
Push an event into the event queue.
Note: provider_name MUST be written onto the event's
channel_name - it decides which channel queue the event belongs
to; dropping it would land all events on the default channel and
channel isolation would break.
源代码位于: zoo_framework/fifo/event_fifo.py
get_top ¶
has_event ¶
Whether the event exists.
Membership check is required: list.index() raises ValueError on
a miss rather than returning -1, and the normal path of this
method's callers (EventChannel.refresh_event,
EventProvider.refresh) is exactly "do nothing on a miss".
源代码位于: zoo_framework/fifo/event_fifo.py
zoo_framework.fifo.delay_fifo.DelayFIFO ¶
Bases: BaseFIFO[DelayFIFONode]
The delayed queue.
源代码位于: zoo_framework/fifo/delay_fifo.py
get_expire_values ¶
Get the expired values.
The original signature carried current_time while the body called
node.is_expire(current_time) - yet
DelayFIFONode.is_expire() takes no argument: by design the
node reads its own monotonic clock (its docstring notes that wall
clock would be misled by NTP corrections or DST jumps), and that
signature is directly exercised by multiple tests in
tests/test_execution_time.py. So the old call raised TypeError at
runtime. The method had no callers, which is why it never
surfaced; the mismatch only became visible to type checking after
_fifo was parameterized as list[DelayFIFONode].
源代码位于: zoo_framework/fifo/delay_fifo.py
zoo_framework.fifo.single_fifo.SingleFIFO ¶
Bases: BaseFIFO[Any]
A single-value queue: the same value enqueues once, with its position recorded.
Note: index_list is still a class attribute (shared across
instances); left unchanged here - a known issue.
源代码位于: zoo_framework/fifo/single_fifo.py
push_value ¶
Enqueue (the same value only once); return the value's position.
Two misuses corrected here:
- list.index() raises ValueError on a miss; it cannot serve as a
"membership check";
- list has no push method; appending uses append.