Scheduler¶
Workflow-based job pipeline. Narrative guide: Scheduler.
Task¶
pypepper.scheduler.task
¶
Scheduler task data structures.
ITask
¶
Bases: IBase
Source code in pypepper/scheduler/task.py
Task
¶
Bases: ITask
Source code in pypepper/scheduler/task.py
Workflow¶
pypepper.scheduler.workflow
¶
Sequential workflow runner over tasks.
IWorkflow
¶
Workflow
¶
Bases: IWorkflow
Source code in pypepper/scheduler/workflow.py
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 | |
add_task
¶
add_tasks
¶
get_tasks
¶
run
¶
Sequentially execute tasks.
Per task:
- round_times outer rounds (default 1); each round has its own retry budget.
Success returns early; later rounds run only after a full failed inner budget.
- round_timeout seconds per execute attempt (0 = none). Timeout counts as a
failed attempt. Queued work is cancelled when possible (timed out before
start). Started work is joined before the next retry or run()
return (execute still running). round_timeout_join bounds that
wait (0 = forever); a still-running Future blocks a later attempt
for the same task. A hung execute with infinite join blocks this workflow /
Worker. Concurrent timeout executes are capped (_SOFT_TIMEOUT_MAX_WORKERS);
further work queues and a short timeout may fire before the task starts.
- Retry modes: until false → retry_count + 1; until + count 0 → per-round
retry_until_max; until + count > 0 → retry_count + 1 (max ignored).
- optional: failed optional tasks continue the workflow.
Non-optional task failure after all rounds/attempts aborts the workflow.
Source code in pypepper/scheduler/workflow.py
Job¶
pypepper.scheduler.job
¶
Job model, processor, and dispatcher.
ChannelEnqueueError
¶
ChannelFullError
¶
Bases: ChannelEnqueueError
Bounded channel capacity rejection (pre-execution; safe to roll back).
ChannelStoppedError
¶
Bases: ChannelEnqueueError
Channel was stopped; enqueue rejected (pre-execution; safe to roll back).
Sibling of :class:ChannelFullError (not a subclass): catch this before treating
:class:ChannelFullError as retryable backpressure. Prefer catching
:class:ChannelEnqueueError for any pre-landing rejection.
Source code in pypepper/scheduler/job.py
JobRedeliveryError
¶
Bases: RuntimeError
Dequeued job could not be returned to the channel after a RUN-start restore
(channel full or stopped). Worker.run_forever re-raises. When reason is
stopped, leftover queued jobs are drained first; full stops immediately.
job is the unrestored instance (not on the channel).
Source code in pypepper/scheduler/job.py
JobRequeuedError
¶
Bases: RuntimeError
Job was restored and put back on the channel after RUN-start persist failure.
Worker.run_forever re-raises (does not continue) so supervisors see a non-success
exit and avoid persist-failure busy-spin; the job remains queued for a later consumer.
Source code in pypepper/scheduler/job.py
Processor
¶
Source code in pypepper/scheduler/job.py
run
¶
Source code in pypepper/scheduler/job.py
async_run
async
staticmethod
¶
Source code in pypepper/scheduler/job.py
Dispatcher
¶
Source code in pypepper/scheduler/job.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 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 | |
dispatch
¶
Source code in pypepper/scheduler/job.py
IJob
¶
Bases: IBase
Source code in pypepper/scheduler/job.py
Job
¶
Bases: IJob
Source code in pypepper/scheduler/job.py
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 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
share_cancel_event
¶
Put this job's cancel Event on every task context (same object execute receives).
Source code in pypepper/scheduler/job.py
is_cancelled
¶
restore_lifecycle
¶
Restore FSM/status after schedule/enqueue failure or RUN-start persist failure.
apply_event
¶
Apply an FSM event or raise if the transition is invalid.
cancel
¶
Cancel a Scheduled or InProgress job and persist Cancelled.
On save() failure the FSM stays Cancelled; retry job.save() only.
Source code in pypepper/scheduler/job.py
to_record
¶
Authoritative lifecycle snapshot from the FSM (may lead durable status).
Source code in pypepper/scheduler/job.py
from_record
classmethod
¶
Rebuild a Job from a store snapshot. Requires registered executor_ids when payload is set.
Leaves the FSM at Unknown (does not restore record.status) so scheduled() can run again.
Source code in pypepper/scheduler/job.py
save
¶
Source code in pypepper/scheduler/job.py
get_saved
staticmethod
¶
Source code in pypepper/scheduler/job.py
log
¶
Channel¶
pypepper.scheduler.channel
¶
Async job channels and channel manager.
Channel
¶
Source code in pypepper/scheduler/channel.py
send
async
¶
Enqueue value.
Returns ok, full, or stopped. The reason is decided under the
same lock as :meth:request_stop (a successful enqueue and a stop-reject
are mutually exclusive). Prefer Job.scheduled() for typed errors.
Source code in pypepper/scheduler/channel.py
receive
async
¶
Wait for the next item, or None when stop wins and the queue is empty.
Cases:
1. stop already set: non-blocking dequeue via get_nowait, or None
if empty (deterministic drain).
2. Live wait: race queue get against the stop event. A completed get
is preferred. If stop wins, drain one ready item via get_nowait so
leftovers are not abandoned.
3. Worker.run_once always calls receive (including after stop) so
queued jobs are processed before the consumer exits.
Do not enqueue None as a job payload: None means stop / empty.
Source code in pypepper/scheduler/channel.py
request_stop
¶
Mark the channel stopped and wake a blocked receive() if needed.
ChannelManager
¶
Source code in pypepper/scheduler/channel.py
put
¶
get
¶
remove
¶
new
¶
Return the channel for key, creating it on first use.
maxsize applies only when the channel is created (0 = unbounded).
If the key already exists, the existing channel is returned and maxsize
is ignored (create bounded channels before Worker/dispatch).
Source code in pypepper/scheduler/channel.py
available
¶
Worker¶
pypepper.scheduler.worker
¶
Channel consumer that runs job workflows.
Worker
¶
Consume jobs from a channel and run their workflows.
Source code in pypepper/scheduler/worker.py
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 | |
run_once
async
¶
run_forever
async
¶
Source code in pypepper/scheduler/worker.py
Executor¶
pypepper.scheduler.executor
¶
Task executor interfaces, callable adapter, and named registry.
IExecutor
¶
Source code in pypepper/scheduler/executor.py
Executor
¶
Bases: IExecutor
No-op executor (placeholder for tasks without work).
Source code in pypepper/scheduler/executor.py
CallableExecutor
¶
Bases: Executor
Executor that runs a provided callable.
Source code in pypepper/scheduler/executor.py
ExecutorRegistry
¶
Explicit process-wide registry of named executor factories.
Source code in pypepper/scheduler/executor.py
Events¶
pypepper.scheduler.events
¶
Scheduler FSM events and builder.
FSM
¶
Per-instance scheduler FSM wrapper (backward-compatible API).
Source code in pypepper/scheduler/events.py
Job store¶
pypepper.scheduler.store
¶
Pluggable job persistence (memory / postgres / mysql / mongodb).
IJobStore
¶
Pluggable persistence for JobRecord snapshots.
Source code in pypepper/scheduler/store/interfaces.py
put
abstractmethod
¶
Upsert by id.
Returns True when the row is inserted or updated, False when the
write is skipped (lifecycle fence or version conflict).
Must not overwrite an existing row's created. Must not replace a
durable status with an earlier lifecycle (for example Scheduled must
not overwrite InProgress/Completed/Failed/Cancelled). Distinct
terminals must not overwrite each other. Same status may update other
fields. Updates require record.version to equal the durable version
(then the stored version is incremented).
Source code in pypepper/scheduler/store/interfaces.py
get
abstractmethod
¶
delete
abstractmethod
¶
list
abstractmethod
¶
JobRecord
dataclass
¶
Job snapshot. Executors are omitted unless payload is present.
Source code in pypepper/scheduler/store/interfaces.py
InMemoryJobStore
¶
Bases: IJobStore
Thread-safe dict-backed job store.
Source code in pypepper/scheduler/store/memory.py
put
¶
Source code in pypepper/scheduler/store/memory.py
get
¶
delete
¶
list
¶
get_job_store
¶
reset_job_store_mismatch_warning
¶
Reset the durable-vs-memory mismatch one-shot warn (tests).
set_job_store
¶
Replace the process-wide job store and clear any deferred durable YAML flag.
Source code in pypepper/scheduler/store/__init__.py
reset_job_store
¶
Reset to a fresh in-memory store (tests / process reset).
Does not acknowledge a deferred durable YAML backend: if the current
config still declares a non-memory jobStore, deferred fail-fast is
re-armed so Job.save cannot silently use memory.
Also clears the durable-vs-memory mismatch one-shot so a later explicit memory install can warn again for the new cycle.
Source code in pypepper/scheduler/store/__init__.py
configure_job_store
¶
Build and install a job store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
Backend
|
|
'memory'
|
**kwargs
|
Any
|
Connection options forwarded to the backend (e.g. |
{}
|
Source code in pypepper/scheduler/store/__init__.py
setup_from_config
¶
Configure job store from YAML scheduler.jobStore (optional).