job_registry
Job registry for centralized job state management.
This module provides a single source of truth for all job state in a workflow, replacing the scattered job tracking across multiple components.
Classes¶
Job
dataclass
¶
Mutable job state container.
Unlike the frozen JobInfo dataclass, this class allows state updates as jobs progress through their lifecycle.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
Unique key for this job (rule + output hash or job_id). |
rule |
str
|
The Snakemake rule name. |
status |
JobStatus
|
Current job status. |
job_id |
str | None
|
Snakemake job ID (may be None initially). |
start_time |
float | None
|
Unix timestamp when job started. |
end_time |
float | None
|
Unix timestamp when job completed. |
wildcards |
dict[str, str]
|
Dictionary of wildcard values. |
threads |
int | None
|
Number of threads allocated. |
input_size |
int | None
|
Total input file size in bytes. |
log_file |
Path | None
|
Path to job's log file. |
external_jobid |
str | None
|
External executor job id/ARN (e.g. AWS Batch), if remote. |
executor |
str | None
|
Remote executor identifier (e.g. "aws-batch"), if applicable. |
region |
str | None
|
Cloud region, used to build console deep links (if known). |
log_stream |
str | None
|
Backend log stream identifier (e.g. CloudWatch stream), if known. |
queued_at |
float | None
|
Epoch seconds the job entered the remote queue, if known. |
queue |
str | None
|
The remote queue / compute environment the job was routed to, if known. |
attempt |
int | None
|
Attempt number for a retried/preempted remote job, if known. |
exit_code |
int | None
|
Container/process exit code for a finished remote job, if known. |
status_reason |
str | None
|
Backend-provided reason string (e.g. failure cause), if any. |
termination_category |
str | None
|
Why the job died (e.g. "spot", "oom"), if classified. |
termination_source |
str | None
|
Provenance of the classification (e.g. "aws_instance_state"). |
termination_confidence |
str | None
|
How sure the producer was ("high" / "low"). |
cost_estimate |
float | None
|
Estimated USD cost of the job (list/market price, not billed). |
Source code in snakesee/state/job_registry.py
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 186 187 188 189 190 191 | |
Attributes¶
queue_wait
property
¶
Seconds spent queued before execution began (remote jobs only).
For a remote job, start_time is the true execution start (from the
executor) and queued_at is when it entered the queue, so their
difference is the queue wait. Returns None when either is unknown.
Methods:¶
from_job_info
classmethod
¶
Create a Job from a JobInfo instance.
Source code in snakesee/state/job_registry.py
to_job_info ¶
to_job_info() -> JobInfo
Convert to immutable JobInfo for backward compatibility.
Source code in snakesee/state/job_registry.py
JobRegistry ¶
Central registry for all job state.
Provides O(1) lookup by job key or job_id, and efficient iteration over jobs by status.
Example
registry = JobRegistry() job = registry.get_or_create("job_1", "align") job.status = JobStatus.RUNNING job.start_time = time.time() registry.update_indexes(job) running = registry.running() # [job]
Source code in snakesee/state/job_registry.py
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 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 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | |
Methods:¶
__contains__ ¶
__init__ ¶
Initialize empty registry.
Source code in snakesee/state/job_registry.py
__len__ ¶
apply_event ¶
apply_event(event: SnakeseeEvent) -> Job | None
Apply a snakesee event to update job state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
SnakeseeEvent
|
The event to apply. |
required |
Returns:
| Type | Description |
|---|---|
Job | None
|
The updated Job, or None if event couldn't be applied. |
Source code in snakesee/state/job_registry.py
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | |
apply_job_info ¶
Add or update a job from a JobInfo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_info
|
JobInfo
|
JobInfo to apply. |
required |
key
|
str | None
|
Optional key. If None, uses job_id or generates one. |
None
|
Returns:
| Type | Description |
|---|---|
Job
|
The created or updated Job. |
Source code in snakesee/state/job_registry.py
clear ¶
Clear all jobs from the registry.
cost_by_rule ¶
Sum of per-job cost estimates grouped by rule (only rules with cost).
Source code in snakesee/state/job_registry.py
get_or_create ¶
get_or_create(key: str, rule: str) -> tuple[Job, bool]
Get existing job or create a new one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Unique job key. |
required |
rule
|
str
|
Rule name for new job. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Job, bool]
|
Tuple of (job, created) where created is True if job was new. |
Source code in snakesee/state/job_registry.py
queued ¶
queued() -> list[Job]
Get all jobs queued on a remote executor (submitted, awaiting a node).
set_status ¶
Update job status and indexes.
store_threads ¶
Store thread count for a job by job_id.
This is used when thread info comes from events before the job is fully tracked.
Source code in snakesee/state/job_registry.py
total_cost_estimate ¶
Sum of per-job cost estimates across all jobs, or None if none have one.
Source code in snakesee/state/job_registry.py
JobStatus ¶
Bases: Enum
Status of a job in the workflow.