dispatch
dispatch
¶
Baton dispatch logic — ready sheet resolution and dispatch.
Called after every event in the baton's main loop. Finds sheets that are ready to execute and dispatches them via a callback, respecting:
- Global concurrency limit (max_concurrent_sheets)
- Per-instrument concurrency limits
- Instrument rate limit state
- Circuit breaker state
- Cost limits (future — checked but not enforced here)
- Backpressure (checked via baton._shutting_down)
The dispatch function is stateless — it reads baton state, makes decisions, and calls the dispatch callback. It does not own any state of its own.
Design notes: - dispatch_ready() is a free function, not a method on BatonCore. This keeps the core focused on state management and event handling. The conductor calls dispatch_ready() after the baton processes each event. - The dispatch callback is async to allow backend acquisition and task creation. - Sheets are marked as 'dispatched' by the callback, not by dispatch_ready(). This ensures that only actually-dispatched sheets consume concurrency slots.
See: docs/plans/2026-03-26-baton-design.md — Dispatch Logic section
Attributes¶
Classes¶
DispatchConfig
dataclass
¶
DispatchConfig(max_concurrent_sheets=10, instrument_concurrency=dict(), model_concurrency=dict(), rate_limited_instruments=set(), open_circuit_breakers=set())
Configuration for the dispatch logic.
Attributes:
| Name | Type | Description |
|---|---|---|
max_concurrent_sheets |
int
|
Global ceiling on concurrent sheet tasks. |
instrument_concurrency |
dict[str, int]
|
Per-instrument concurrency limits (fallback when no model-specific limit exists). |
model_concurrency |
dict[str, int]
|
Per-(instrument, model) concurrency limits.
Keys are |
rate_limited_instruments |
set[str]
|
Set of instrument names currently rate-limited. |
open_circuit_breakers |
set[str]
|
Set of instrument names with open circuit breakers. |
DispatchResult
dataclass
¶
Functions¶
dispatch_ready
async
¶
Find and dispatch all sheets that are ready to execute.
Called after every event in the baton's main loop. This is the only place where sheets move from 'pending'/'ready' to 'dispatched'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
baton
|
BatonCore
|
The baton core (provides sheet state and job registry). |
required |
config
|
DispatchConfig
|
Dispatch configuration (concurrency limits, etc.). |
required |
callback
|
DispatchCallback
|
Async function called for each sheet to dispatch. Receives (job_id, sheet_num, sheet_state). |
required |
Returns:
| Type | Description |
|---|---|
DispatchResult
|
DispatchResult with counts of dispatched and skipped sheets. |
Source code in src/marianne/daemon/baton/dispatch.py
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 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |