Work Queue API¶
Brokerless work queues: a QueueRole owner (enqueue / claim / ack / nack + lease
sweeper) and the competing-consumer worker loop. QueueStore holds the job
state in memory and writes it through to the app's StoragePlugin.
Guide: Work Queues.
Work queues: jobs, not events. See docs/user-guide/work-queues.md.
CronError
¶
CronSchedule
¶
A parsed cron expression that can compute its next firing time.
Source code in src/istos/queue/cron.py
next_after(after)
¶
The first firing strictly after after (minute resolution).
Source code in src/istos/queue/cron.py
JobContext
dataclass
¶
What the queue knows about this delivery of a job.
A worker that names a ctx parameter is handed one, the same way a handler
that names db is handed the app's storage::
@app.worker("jobs/email")
async def send(job, ctx: JobContext):
if ctx.is_last_attempt:
log.warning("final try for %s: %s", ctx.job_id, ctx.last_error)
The job body stays exactly what was enqueued — delivery metadata lives here rather than being mixed into the caller's data.
Source code in src/istos/queue/store.py
QueueRole
¶
The queue owner. Binds enqueue / claim / ack / nack / result queryables on the shared session, publishes a nudge when a job arrives, and reclaims expired leases on a timer. One owner per queue.
Source code in src/istos/queue/role.py
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 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
is_active
property
¶
Whether this node is the queue's live owner right now — always, without
ha; only the elected leader with it. Used to run a co-located
:meth:schedule beat on exactly one node.
QueueStore
¶
Authoritative job state for one queue, held in the owner's memory and
(optionally) written through to a StoragePlugin so it survives a restart.
A single owner serializes every mutation through _lock, which is what
makes claim/ack atomic without a database transaction — there is only ever
one writer.
Source code in src/istos/queue/store.py
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 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
chord_report(chord_id, index, size, result)
async
¶
Record one chord member's completion. Returns the collected results (in member order) exactly once — to the caller that completes the barrier — and None for every earlier member. Results are base64 strings (or None).
Source code in src/istos/queue/store.py
claim(*, lease_s)
async
¶
Lease the highest-priority eligible job (FIFO within a priority) in O(log n): pop the ready heap, skipping stale entries. Matures delayed jobs and reclaims expired leases first. Returns a copy so callers can't mutate state off-lock.
Source code in src/istos/queue/store.py
load()
async
¶
Recover state from storage on bind. No-op for the in-memory default.
Source code in src/istos/queue/store.py
nack(job_id, *, error=None, retry_delay_s=0.0)
async
¶
Fail a leased job. Redelivers (after retry_delay_s) if attempts
remain, else dead-letters. Returns "requeued" or "dead" (or None if
the job is unknown).
Source code in src/istos/queue/store.py
result(job_id)
async
¶
Return (state, result_bytes) for a job. State is "unknown" once the
job (and its retained result) is gone.
Source code in src/istos/queue/store.py
sweep()
async
¶
Reclaim jobs whose lease expired (worker crashed without ack) and purge results past their TTL. Returns how many leases were reclaimed.
Source code in src/istos/queue/store.py
worker_wrapper
¶
A competing consumer. Runs concurrency claim→run→ack loops against a
queue owner elsewhere on the mesh, waking on the owner's nudge instead of busy
polling. The handler returning acks the job (and hands back its result); the
handler raising nacks it (redeliver with backoff, then dead-letter).
Source code in src/istos/queue/worker.py
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 | |