API Reference¶
This section contains the API documentation for Jobify, automatically generated from the source code.
jobify
¶
Core scheduling components for the jobify framework.
This module provides the basic classes for job scheduling and management. It exposes the main scheduler interface and job planning components that form the basis of the jobify asynchronous job scheduling system.
INJECT = object()
module-attribute
¶
Cron
dataclass
¶
Configuration for cron-based job scheduling.
Attributes:
| Name | Type | Description |
|---|---|---|
expression |
str
|
The crontab-formatted expression. |
max_runs |
int
|
Maximum number of times the job can be triggered. Defaults to infinity. |
max_failures |
int
|
Maximum number of consecutive failures before disabling the job. Defaults to 10. |
misfire_policy |
MisfirePolicy | GracePolicy
|
Policy to handle missed job executions. Defaults to MisfirePolicy.ONCE. |
start_date |
datetime | None
|
Optional datetime when the cron job becomes active. |
args |
tuple[Any, ...]
|
Positional arguments to pass to the job. |
kwargs |
dict[str, Any]
|
Keyword arguments to pass to the job. |
Source code in src/jobify/_internal/configuration.py
CronContext
¶
Bases: Generic[ReturnT]
Holds configuration and state for a cron-based job.
Attributes:
| Name | Type | Description |
|---|---|---|
cron |
The cron configuration. |
|
cron_parser |
The parser used to calculate next run times. |
|
failure_count |
Number of consecutive failures. |
|
job |
The associated job instance. |
|
offset |
The base datetime from which the next run is calculated. |
|
run_count |
Number of times this job has been executed. |
Source code in src/jobify/_internal/scheduler/job.py
__init__(*, cron, cron_parser, failure_count=0, job, offset, run_count)
¶
Initialize the CronContext.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cron
|
Cron
|
The cron configuration. |
required |
cron_parser
|
CronParser
|
The parser used to calculate next run times. |
required |
failure_count
|
int
|
Initial failure count. |
0
|
job
|
Job[ReturnT]
|
The associated job instance. |
required |
offset
|
datetime
|
The base datetime. |
required |
run_count
|
int
|
Initial run count. |
required |
Source code in src/jobify/_internal/scheduler/job.py
is_failure_allowed_by_limit()
¶
Check if the job can still fail based on the allowed limit.
Returns:
| Type | Description |
|---|---|
bool
|
True if the failure limit has not been reached, False otherwise. |
Source code in src/jobify/_internal/scheduler/job.py
is_run_exceeded_by_limit()
¶
Check if the maximum number of runs has been exceeded.
Returns:
| Type | Description |
|---|---|
bool
|
True if the run limit is reached, False otherwise. |
Source code in src/jobify/_internal/scheduler/job.py
GracePolicy
¶
Bases: NamedTuple
Grace period policy for handling misfired jobs.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
timedelta
|
The duration of the grace period. |
Source code in src/jobify/_internal/scheduler/misfire_policy.py
Job
¶
Bases: Generic[ReturnT]
Represents a scheduled job.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Unique identifier for the job. |
|
status |
Current status of the job. |
|
exec_at |
The scheduled execution time. |
|
exception |
Exception | None
|
The exception raised, if any. |
Source code in src/jobify/_internal/scheduler/job.py
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 | |
cron_expression
property
¶
Return the cron expression if this is a cron job, else None.
__init__(*, job_id, storage, exec_at, unregister_hook, job_status=JobStatus.PENDING)
¶
Initialize the Job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Unique identifier for the job. |
required |
storage
|
Storage
|
Storage backend. |
required |
exec_at
|
datetime
|
The scheduled execution time. |
required |
unregister_hook
|
Callable[[str], None]
|
Callback to unregister the job. |
required |
job_status
|
JobStatus
|
Initial status of the job. |
PENDING
|
Source code in src/jobify/_internal/scheduler/job.py
bind_cron_context(ctx)
¶
Bind a cron context to the job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
CronContext[ReturnT]
|
The cron context to bind. |
required |
bind_handle(handle)
¶
Bind an asyncio handle to the job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handle
|
Handle
|
The handle to bind. |
required |
cancel()
async
¶
is_cron()
¶
Check if this is a cron job.
Returns:
| Type | Description |
|---|---|
bool
|
True if it's a cron job, False otherwise. |
is_done()
¶
Check if the job is done.
Returns:
| Type | Description |
|---|---|
bool
|
True if the job is done, False otherwise. |
is_reschedulable()
¶
Check if the job can be rescheduled.
Returns:
| Type | Description |
|---|---|
bool
|
True if reschedulable, False otherwise. |
Source code in src/jobify/_internal/scheduler/job.py
result()
¶
Return the result of the job.
Returns:
| Type | Description |
|---|---|
ReturnT
|
The job result. |
Raises:
| Type | Description |
|---|---|
JobFailedError
|
If the job failed. |
JobNotCompletedError
|
If the job is not yet completed. |
Source code in src/jobify/_internal/scheduler/job.py
set_exception(exc, *, status)
¶
Set the exception for the job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc
|
Exception
|
The exception to set. |
required |
status
|
JobStatus
|
The status to set. |
required |
Source code in src/jobify/_internal/scheduler/job.py
set_result(val, *, status)
¶
Set the result of the job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val
|
ReturnT
|
The job result. |
required |
status
|
JobStatus
|
The status to set. |
required |
update(*, exec_at, status)
¶
Update the job schedule and status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exec_at
|
datetime
|
The new scheduled time. |
required |
status
|
JobStatus
|
The new status. |
required |
Source code in src/jobify/_internal/scheduler/job.py
wait()
async
¶
Wait until the job is done.
If the job is already completed, this method returns immediately. Safe for concurrent use by multiple coroutines.
JobContext
¶
Bases: NamedTuple
Context object injected into jobs at runtime.
Provides access to job execution context, allowing jobs to inspect their configuration, state, and scheduling builder.
Attributes:
| Name | Type | Description |
|---|---|---|
job |
Job[Any]
|
The job instance. |
state |
State
|
The global application state. |
runnable |
Runnable[Any]
|
The runnable component. |
request_state |
RequestState
|
State specific to the current request. |
route_options |
RouteOptions
|
Configuration options for the route. |
jobify_config |
JobifyConfiguration
|
Global Jobify configuration. |
schedule_builder |
ScheduleBuilder[Any]
|
Builder used to construct the schedule. |
Source code in src/jobify/_internal/context.py
JobRouter
¶
Bases: Router
Router for organizing jobs and sub-routers.
NodeRouter is a container for routes and sub-routers, providing
a way to structure large applications by grouping related jobs together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State | None
|
Optional initial state for the router. |
None
|
prefix
|
str | None
|
Optional prefix for route names. |
None
|
lifespan
|
Lifespan[NodeRouter_co] | None
|
Optional lifespan handler for the router. |
None
|
middleware
|
Sequence[BaseMiddleware] | None
|
Middleware to apply to jobs in this router. |
None
|
outer_middleware
|
Sequence[BaseOuterMiddleware] | None
|
Middleware to apply to scheduling process. |
None
|
exception_handlers
|
MappingExceptionHandlers | None
|
Exception handlers for jobs. |
None
|
route_class
|
type[NodeRoute[..., Any]]
|
Class to use for creating new routes. |
NodeRoute
|
Source code in src/jobify/_internal/router/node.py
JobStatus
¶
Bases: str, Enum
The status of a job.
Attributes:
| Name | Type | Description |
|---|---|---|
PENDING |
Job is waiting to be processed. |
|
SCHEDULED |
Job is scheduled for future execution. |
|
RUNNING |
Job is currently executing. |
|
CANCELLED |
Job was cancelled. |
|
SUCCESS |
Job completed successfully. |
|
FAILED |
Job failed execution. |
|
TIMEOUT |
Job timed out. |
|
PERMANENTLY_FAILED |
Job failed and exhausted all retry attempts. |
Source code in src/jobify/_internal/common/constants.py
Jobify
¶
Bases: RootRouter
Jobify is the main app for scheduling and managing background jobs.
It provides a flexible and extensible framework for defining, running, and persisting jobs, supporting various executors, middleware, and serialization options.
Attributes:
| Name | Type | Description |
|---|---|---|
configs |
JobifyConfiguration
|
Configuration object for the application. |
plugins |
set[Plugin]
|
Set of registered plugins. |
Source code in src/jobify/jobify.py
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 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 | |
__aenter__()
async
¶
Enter the Jobify context manager.
Returns:
| Type | Description |
|---|---|
Self
|
The initialized Jobify instance ready for use. |
Raises:
| Type | Description |
|---|---|
Exception
|
Any exception raised by |
Source code in src/jobify/jobify.py
__aexit__(_exc_type=None, _exc_val=None, _exc_tb=None)
async
¶
Exit the Jobify context manager.
Note
This method ensures proper shutdown regardless of whether an exception occurred in the managed context. The exception parameters are ignored as shutdown should proceed even if the context failed.
Source code in src/jobify/jobify.py
__init__(*, tz=None, state=None, dumper=None, loader=None, storage=UNSET, lifespan=None, serializer=None, middleware=None, outer_middleware=None, cron_factory=create_crontab, loop_factory=asyncio.get_running_loop, exception_handlers=None, threadpool_executor=None, processpool_executor=None, route_class=RootRoute, plugins=(), uuid_generator=uuid.uuid4)
¶
Initialize a Jobify instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tz
|
ZoneInfo | None
|
Timezone info, defaults to UTC. |
None
|
state
|
State | None
|
Optional initial application state. |
None
|
dumper
|
Dumper | None
|
Dumper for serialization. |
None
|
loader
|
Loader | None
|
Loader for deserialization. |
None
|
storage
|
Storage | Literal[False]
|
Storage backend, defaults to SQLite if not provided. |
UNSET
|
lifespan
|
Lifespan[AppT] | None
|
Optional lifespan handler. |
None
|
serializer
|
Serializer | None
|
Serializer for job messages. |
None
|
middleware
|
Sequence[BaseMiddleware] | None
|
List of middleware components. |
None
|
outer_middleware
|
Sequence[BaseOuterMiddleware] | None
|
List of outer middleware components. |
None
|
cron_factory
|
CronFactory
|
Factory function for cron parsing. |
create_crontab
|
loop_factory
|
LoopFactory
|
Factory function for the event loop. |
get_running_loop
|
exception_handlers
|
MappingExceptionHandlers | None
|
Mapping of exception types to handlers. |
None
|
threadpool_executor
|
ThreadPoolExecutor | None
|
Executor for thread-based jobs. |
None
|
processpool_executor
|
ProcessPoolExecutor | None
|
Executor for process-based jobs. |
None
|
route_class
|
type[RootRoute[..., Any]]
|
Class to use for root routes. |
RootRoute
|
plugins
|
Sequence[Plugin]
|
List of plugins to register. |
()
|
uuid_generator
|
UUIDGenerator
|
uuid generator factory. |
uuid4
|
Source code in src/jobify/jobify.py
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 | |
add_plugin(plug)
¶
find_job(id_)
¶
get_active_jobs()
¶
shutdown()
async
¶
Gracefully shut down the Jobify application.
This method performs a structured shutdown:
1. Marks the application as stopped (app_started = False).
2. Propagates shutdown events to all routers/components.
3. Cancels all scheduled future jobs in the registry
(_jobs_registry).
4. Closes the jobify configuration (e.g., stopping the internal
scheduler).
5. Cancels all currently running tasks (in _tasks_registry), waits
for their completion, and explicitly clears the task registry.
Note
The method uses return_exceptions=True when gathering cancelled
tasks to prevent shutdown from being interrupted by task exception.
Source code in src/jobify/jobify.py
startup()
async
¶
Initialize the Jobify application.
This method: 1. Marks the application as started 2. Propagates startup events to all routers and their registrators 3. Schedules any pending cron jobs
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If application startup fails due to configuration issues or router initialization errors. |
Source code in src/jobify/jobify.py
wait_all(timeout=None)
async
¶
Wait for all currently scheduled jobs to complete.
This method waits until all jobs currently registered have finished executing (with statuses of SUCCESS, FAILED, or TIMEOUT). This is useful in situations where it's important to ensure that background tasks have completed before moving on.
The method sets an internal event when both conditions are met:
1. No jobs remain in the jobs registry (_jobs_registry)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
optional
|
The maximum time in seconds to wait for the
jobs to complete. If not specified, the default value of |
None
|
Source code in src/jobify/jobify.py
MisfirePolicy
¶
Bases: str, Enum
Policy for handling jobs that missed their scheduled run time.
Attributes:
| Name | Type | Description |
|---|---|---|
ALL |
Run all missed executions. |
|
SKIP |
Skip missed executions and schedule the next one. |
|
ONCE |
Run once immediately. |
Source code in src/jobify/_internal/scheduler/misfire_policy.py
OuterContext
¶
Context object passed to middleware during the scheduling process.
This object holds all information required to inspect, modify, or intercept a job before it is officially scheduled.
Attributes:
| Name | Type | Description |
|---|---|---|
job |
The job instance being scheduled. |
|
state |
The global application state. |
|
trigger |
The trigger mechanism (e.g., Cron, Push). |
|
runnable |
The runnable component (function/method) being scheduled. |
|
arguments |
The arguments bound to the job function. |
|
func_spec |
Inspection details of the job function. |
|
is_force |
Whether the job is forced to run. |
|
is_persist |
Whether the job should be persisted to storage. |
|
is_replace |
Whether the job replaces an existing one. |
|
route_options |
Configuration options for the route. |
|
jobify_config |
Global Jobify configuration. |
|
request_state |
State specific to the current request. |
|
persist_job_hook |
Callback to persist the job. |
|
schedule_hook |
Callback to schedule the job. |
|
schedule_builder |
Builder used to construct the schedule. |
Source code in src/jobify/_internal/context.py
Plugin
¶
Bases: Protocol
Lifecycle hooks for integrating extensions into a Jobify app.
Source code in src/jobify/jobify.py
shutdown()
async
¶
RequestState
¶
RunMode
¶
Bases: str, Enum
The execution mode of a job.
Attributes:
| Name | Type | Description |
|---|---|---|
MAIN |
Execute in the main event loop. |
|
THREAD |
Execute in a worker thread. |
|
PROCESS |
Execute in a worker process. |
Source code in src/jobify/_internal/common/constants.py
Runnable
¶
Bases: Generic[ReturnT]
Represents a job function that is ready for execution.
Runnable encapsulates the function, its bound arguments, and the
execution strategy (async, thread pool, or process pool).
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the job. |
strategy |
RunStrategy[..., ReturnT]
|
The execution strategy used to run the job. |
bound |
BoundArguments
|
The bound arguments of the job function. |
origin_arguments |
The original arguments before any modifications. |
|
func_spec |
Inspection details of the job function. |
Source code in src/jobify/_internal/runners.py
ScheduleBuilder
¶
Bases: Generic[ReturnT]
Builder class for scheduling jobs.
This class provides methods to schedule tasks to run immediately (push), at a specific time (at), or according to a cron schedule (cron).
Attributes:
| Name | Type | Description |
|---|---|---|
func_spec |
FuncSpec[ReturnT]
|
Function specification. |
name |
str
|
Name of the scheduled task. |
route_options |
RouteOptions
|
Route options for the task. |
Source code in src/jobify/_internal/scheduler/scheduler.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 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 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 | |
__init__(*, name, state, task_tracker, jobify_config, runnable, chain_middleware, chain_outer_middleware, func_spec, exception_handlers, options, is_persist)
¶
Initialize the ScheduleBuilder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The task name. |
required |
state
|
State
|
Application state. |
required |
task_tracker
|
TaskTracker
|
Tracker for scheduled tasks. |
required |
jobify_config
|
JobifyConfiguration
|
Jobify configuration. |
required |
runnable
|
Runnable[ReturnT]
|
The runnable task. |
required |
chain_middleware
|
CallNext
|
Middleware for task execution. |
required |
chain_outer_middleware
|
CallNextOuter
|
Middleware for scheduling. |
required |
func_spec
|
FuncSpec[ReturnT]
|
Function specification. |
required |
exception_handlers
|
ExceptionHandlers
|
Exception handlers. |
required |
options
|
RouteOptions
|
Route options. |
required |
is_persist
|
bool
|
Whether the schedule should be persisted. |
required |
Source code in src/jobify/_internal/scheduler/scheduler.py
at(at, *, job_id=None, replace=False, force=False)
async
¶
Schedules a task to run at a specific time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
at
|
datetime
|
The scheduled datetime. |
required |
job_id
|
str | None
|
Unique identifier for the job. |
None
|
replace
|
bool
|
Whether to replace an existing job. |
False
|
force
|
bool
|
Whether to force scheduling even if already scheduled at this time. |
False
|
Returns:
| Type | Description |
|---|---|
Job[ReturnT]
|
The scheduled Job instance. |
Source code in src/jobify/_internal/scheduler/scheduler.py
cron(cron, *, job_id, replace=False, force=False)
async
¶
Schedules a task based on a cron expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cron
|
str | Cron
|
Cron expression string or object. |
required |
job_id
|
str
|
Unique identifier for the job. |
required |
replace
|
bool
|
Whether to replace an existing job if it exists. |
False
|
force
|
bool
|
Whether to force scheduling even if parameters match. |
False
|
Returns:
| Type | Description |
|---|---|
Job[ReturnT]
|
The scheduled Job instance. |
Source code in src/jobify/_internal/scheduler/scheduler.py
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 | |
delay(seconds, *, job_id=None, now=None, replace=False)
async
¶
Schedules a task to run after a delay.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
float
|
Delay in seconds. |
required |
job_id
|
str | None
|
Unique identifier for the job. |
None
|
now
|
datetime | None
|
Current time base. |
None
|
replace
|
bool
|
Whether to replace an existing job. |
False
|
Returns:
| Type | Description |
|---|---|
Job[ReturnT]
|
The scheduled Job instance. |
Source code in src/jobify/_internal/scheduler/scheduler.py
now()
¶
Return the current datetime in the configured timezone.
Returns:
| Type | Description |
|---|---|
datetime
|
Current datetime. |
push()
async
¶
Schedules a task to run immediately.
Returns:
| Type | Description |
|---|---|
Job[ReturnT]
|
The scheduled Job instance. |
Source code in src/jobify/_internal/scheduler/scheduler.py
SmartRetry
¶
Bases: NamedTuple
Immutable configuration and delay logic for retrying failed operations.
Uses exponential backoff with optional equal jitter to spread retry load. Designed as a value object: cheap to copy, safe to share across threads.
Attributes:
| Name | Type | Description |
|---|---|---|
retries |
int
|
Number of retries that should be performed after the first failure. Must be >= 0. A value of 0 means no retries. |
initial_delay |
float
|
Base delay in seconds before the first retry. |
max_delay |
float
|
Upper bound on computed delay, regardless of backoff growth. |
backoff_factor |
float
|
Multiplier applied per retry. |
jitter |
bool
|
If |
include_exceptions |
tuple[type[Exception], ...]
|
Exception types that trigger a retry. Defaults to ``(Exception,) — retries on anything. |
exclude_exceptions |
tuple[type[Exception], ...]
|
Exception types that are re-raised immediately,
even if they match |
Source code in src/jobify/_internal/configuration.py
State
¶
Bases: UserDict[str, Any]
An object that can be used to store arbitrary state.
This class provides dictionary-like access to state data, allowing for both key-based and attribute-based access.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
dict[str, Any] | None
|
Initial state dictionary. |
None
|
Source code in src/jobify/_internal/common/datastructures.py
jobify.serializers
¶
Serializers module for Jobify.
This module provides serialization utilities for task data and results.
Available serializers implement the Serializer protocol.
Classes:
| Name | Description |
|---|---|
Serializer |
Abstract base protocol defining serializer interface |
JSONSerializer |
Standard JSON serializer |
ExtendedJSONSerializer |
JSON serializer supporting extended types |
CBORSerializer |
CBOR binary format serializer |
MsgpackSerializer |
Msgpack binary format serializer |
OrjsonSerializer |
High-performance JSON serializer (using |
UnsafePickleSerializer |
Pickle-based serializer (use with caution) |
Protocol Interface
dumpb(value: Any) -> bytes: Serialize object to bytes loadb(value: bytes) -> Any: Deserialize bytes to object
Security Notes
- JSON, CBOR, Msgpack, Orjson: Generally safe for data exchange.
- UnsafePickleSerializer: UNSAFE for untrusted data - allows arbitrary code execution.
Serializer
¶
Bases: Protocol
Interface for serializing and deserializing job messages.
Source code in src/jobify/_internal/serializers/base.py
dumpb(data)
abstractmethod
¶
CBORSerializer
¶
Bases: Serializer
Serialize and deserialize data using the cbor2 library.
See https://cbor2.readthedocs.io/en/stable/ for more information.
Source code in src/jobify/serializers/cbor.py
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 | |
__init__(*, datetime_as_timestamp=False, timezone=None, value_sharing=False, encoders=None, default=None, canonical=False, date_as_datetime=False, string_referencing=False, indefinite_containers=False, tag_hook=None, object_hook=None, semantic_decoders=None, str_errors='strict', max_depth=400, allow_indefinite=True, immutable=False)
¶
Initialize the CBOR serializer with encoder and decoder options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datetime_as_timestamp
|
bool
|
Serialize datetimes as UNIX timestamps. Makes datetimes more concise on the wire, but loses timezone info. |
False
|
timezone
|
tzinfo | None
|
Default timezone for naive datetimes. If not set, naive
datetimes raise |
None
|
value_sharing
|
bool
|
Allow efficient serialization of repeated values and cyclic data structures, at the cost of extra overhead. |
False
|
encoders
|
Mapping[type, EncoderHook] | None
|
Mapping of Python types to encoder hooks, overriding the default encoding for those types. |
None
|
default
|
EncoderHook | None
|
Fallback encoder hook called when no suitable encoder is found for a value. |
None
|
canonical
|
bool
|
Use canonical CBOR representation (e.g. sorted maps/sets), ensuring serializations are comparable without decoding. |
False
|
date_as_datetime
|
bool
|
Serialize |
False
|
string_referencing
|
bool
|
Allow more efficient serialization of repeated string values. |
False
|
indefinite_containers
|
bool
|
Encode containers as indefinite-length using a stop code instead of an explicit length prefix. |
False
|
tag_hook
|
TagHook | None
|
Decoder hook for CBOR tags with no built-in decoder. Called
with the |
None
|
object_hook
|
ObjectHook | None
|
Decoder hook called for each deserialized |
None
|
semantic_decoders
|
SemanticDecoders
|
Mapping of semantic tag numbers to decoder callbacks, overriding the default decoding for those tags. |
None
|
str_errors
|
str
|
Unicode error handler for string decoding (e.g.
|
'strict'
|
max_depth
|
int
|
Maximum allowed nesting depth for containers. |
400
|
allow_indefinite
|
bool
|
If |
True
|
immutable
|
bool
|
Return immutable types ( |
False
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If cbor2 is not installed. |
Source code in src/jobify/serializers/cbor.py
dumpb(data)
¶
Serialize data to CBOR bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
JSONCompat
|
The value to serialize. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
CBOR-encoded bytes. |
Source code in src/jobify/serializers/cbor.py
loadb(data)
¶
Deserialize CBOR bytes to a Python object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
CBOR-encoded bytes to deserialize. |
required |
Returns:
| Type | Description |
|---|---|
JSONCompat
|
The deserialized Python object. |
Source code in src/jobify/serializers/cbor.py
MsgpackSerializer
¶
Bases: Serializer
Serialize and deserialize data using the msgpack library.
See https://msgpack-python.readthedocs.io for more information.
Source code in src/jobify/serializers/msgpack.py
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 | |
__init__(*, default=None, use_bin_type=True, strict_types=False, datetime=False, unicode_errors=None, raw=False, timestamp=0, strict_map_key=True, use_list=True, object_hook=None, object_pairs_hook=None, list_hook=None, ext_hook=None, max_str_len=-1, max_bin_len=-1, max_array_len=-1, max_map_len=-1, max_ext_len=-1)
¶
Initialize the MessagePack serializer with packer and unpacker options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default
|
Callable[[Any], Any] | None
|
Callable invoked for types not natively supported by
msgpack. Should return a msgpack-serializable value or raise
|
None
|
use_bin_type
|
bool
|
Use the msgpack 2.0 |
True
|
strict_types
|
bool
|
If |
False
|
datetime
|
bool
|
If |
False
|
unicode_errors
|
str | None
|
Error handler for encoding unicode strings
(e.g. |
None
|
raw
|
bool
|
If |
False
|
timestamp
|
int
|
Controls how msgpack
|
0
|
strict_map_key
|
bool
|
If |
True
|
use_list
|
bool
|
If |
True
|
object_hook
|
Callable[[dict[Any, Any]], Any] | None
|
Callable invoked with each deserialized |
None
|
object_pairs_hook
|
Callable[[list[tuple[Any, Any]]], Any] | None
|
Callable invoked with a list of |
None
|
list_hook
|
Callable[[list[Any]], Any] | None
|
Callable invoked with each deserialized |
None
|
ext_hook
|
Callable[[int, bytes], Any] | None
|
Callable invoked for ext types with no built-in decoder.
Receives |
None
|
max_str_len
|
int
|
Maximum allowed byte length for |
-1
|
max_bin_len
|
int
|
Maximum allowed byte length for |
-1
|
max_array_len
|
int
|
Maximum allowed number of elements in arrays.
|
-1
|
max_map_len
|
int
|
Maximum allowed number of key-value pairs in maps.
|
-1
|
max_ext_len
|
int
|
Maximum allowed byte length for ext type data.
|
-1
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If msgpack is not installed. |
Source code in src/jobify/serializers/msgpack.py
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 | |
dumpb(data)
¶
Serialize data to MessagePack bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
JSONCompat
|
The value to serialize. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
MessagePack-encoded bytes. |
Source code in src/jobify/serializers/msgpack.py
loadb(data)
¶
Deserialize MessagePack bytes to a Python object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
MessagePack-encoded bytes to deserialize. |
required |
Returns:
| Type | Description |
|---|---|
JSONCompat
|
The deserialized Python object. |
Source code in src/jobify/serializers/msgpack.py
OrjsonSerializer
¶
Bases: Serializer
Serialize and deserialize data using the orjson library.
See https://github.com/ijl/orjson for more information.
Source code in src/jobify/serializers/orjson.py
__init__(*, default=None, option=None)
¶
Initialize the orjson serializer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default
|
Callable[[Any], Any] | None
|
Callable invoked for types not natively supported by
orjson. Should return a JSON-serializable value or raise
|
None
|
option
|
int | None
|
Bitmask of |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If orjson is not installed. |
Source code in src/jobify/serializers/orjson.py
dumpb(data)
¶
Serialize data to JSON bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
JSONCompat
|
The value to serialize. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
JSON-encoded bytes. |
Source code in src/jobify/serializers/orjson.py
loadb(data)
¶
Deserialize JSON bytes to a Python object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
JSON-encoded bytes to deserialize. |
required |
Returns:
| Type | Description |
|---|---|
JSONCompat
|
The deserialized Python object. |
Source code in src/jobify/serializers/orjson.py
JSONSerializer
¶
ExtendedJSONSerializer
¶
Bases: Serializer
Source code in src/jobify/_internal/serializers/json_extended.py
UnsafePickleSerializer
¶
Bases: Serializer
Source code in src/jobify/_internal/serializers/pickle_unsafe.py
jobify.typeadapter
¶
Type adaptation and serialization utilities.
This module provides base classes and interfaces for converting Python types to serializable formats and back. It serves as the foundation for type adaptation, leveraging implementations from pydantic and adaptix.
The module exports the main type adaptation interfaces: - Dumper: Base class for serializing Python objects to JSON-compatible types - Loader: Base class for deserializing JSON-compatible types to Python objects
Dumper
¶
Bases: Protocol
Interface for dumping objects into a serializable format.
Source code in src/jobify/_internal/typeadapter/base.py
Loader
¶
Bases: Protocol
Interface for loading data into typed objects.
Source code in src/jobify/_internal/typeadapter/base.py
PydanticConverter
¶
Load and dump data using pydantic's TypeAdapter.
See https://docs.pydantic.dev/latest/api/type_adapter/ for more information.
Source code in src/jobify/typeadapter/pydantic.py
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 | |
__init__(*, config=None, strict=None, from_attributes=None, by_alias=False, exclude_none=False, context=None)
¶
Initialize the pydantic converter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ConfigDict | None
|
Pydantic |
None
|
strict
|
bool | None
|
If |
None
|
from_attributes
|
bool | None
|
If |
None
|
by_alias
|
bool
|
If |
False
|
exclude_none
|
bool
|
If |
False
|
context
|
dict[str, Any] | None
|
Arbitrary context object passed to validators and
serializers that accept a |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If pydantic is not installed. |
Source code in src/jobify/typeadapter/pydantic.py
dump(data, tp)
¶
Serialize an object to a JSON-compatible Python structure.
Converts complex types such as dataclasses, Pydantic models, enums,
and datetimes into plain dict, list, str, int,
float, bool, or None values suitable for any binary
serializer (e.g. orjson, cbor2, msgpack).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The object to serialize. |
required |
tp
|
Any
|
The type whose pydantic schema governs serialization. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A JSON-compatible Python object. |
Source code in src/jobify/typeadapter/pydantic.py
load(data, tp)
¶
Validate and coerce data into the specified type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The raw input to validate. |
required |
tp
|
type[T]
|
The target type to validate against. |
required |
Returns:
| Type | Description |
|---|---|
T
|
The validated and coerced object of type |
Source code in src/jobify/typeadapter/pydantic.py
jobify.router
¶
Module with all the main stuff for organizing and managing tasks in Jobify.
Includes JobRouter for grouping tasks into logical units, and RootRoute and NodeRoute classes as basis for task execution and hierarchical routing.
Route
¶
Bases: ABC, Generic[ParamsT, Return_co]
Source code in src/jobify/_internal/router/base.py
JobRouter
¶
Bases: Router
Router for organizing jobs and sub-routers.
NodeRouter is a container for routes and sub-routers, providing
a way to structure large applications by grouping related jobs together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State | None
|
Optional initial state for the router. |
None
|
prefix
|
str | None
|
Optional prefix for route names. |
None
|
lifespan
|
Lifespan[NodeRouter_co] | None
|
Optional lifespan handler for the router. |
None
|
middleware
|
Sequence[BaseMiddleware] | None
|
Middleware to apply to jobs in this router. |
None
|
outer_middleware
|
Sequence[BaseOuterMiddleware] | None
|
Middleware to apply to scheduling process. |
None
|
exception_handlers
|
MappingExceptionHandlers | None
|
Exception handlers for jobs. |
None
|
route_class
|
type[NodeRoute[..., Any]]
|
Class to use for creating new routes. |
NodeRoute
|
Source code in src/jobify/_internal/router/node.py
NodeRoute
¶
Bases: Route[ParamsT, ReturnT]
Source code in src/jobify/_internal/router/node.py
RootRoute
¶
Bases: Route[ParamsT, ReturnT]
Source code in src/jobify/_internal/router/root.py
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 | |
jobify.middleware
¶
Middleware system for job execution pipeline.
This module provides a basic interface for creating middleware that can intercept and process jobs before they reach their final destination. Middleware can be combined together to create a processing chain, where each piece of middleware can:
- Execute code before the job is handled
- Pass control to the next middleware in the pipeline
- Execute code after the job has been handled
- Modify the state or the result
- Break out of the chain by skipping the
call_next()method
CallNext = Callable[[JobContext], Awaitable[Any]]
module-attribute
¶
CallNextOuter = Callable[[OuterContext], Awaitable[asyncio.Handle]]
module-attribute
¶
BaseMiddleware
¶
BaseOuterMiddleware
¶
JobifyQueue
¶
QueueMiddleware
¶
Bases: BaseMiddleware
Source code in src/jobify/_internal/middleware/queue.py
jobify.exceptions
¶
Custom exceptions for the jobify framework.
This module defines specific exceptions that the jobify scheduling system can raise. These exceptions provide more detailed information about errors and guidance on how to handle common scheduling scenarios.
ApplicationStateError
¶
Bases: BaseJobifyError
Raised when app is in wrong state for the requested operation.
Source code in src/jobify/_internal/exceptions.py
BaseJobifyError
¶
DuplicateJobError
¶
Bases: RuntimeError
Raised when a job is scheduled with an ID that is already in use.
Source code in src/jobify/_internal/exceptions.py
JobFailedError
¶
JobNotCompletedError
¶
Bases: BaseJobifyError
Raised when trying to access result of incomplete job.
Source code in src/jobify/_internal/exceptions.py
JobTimeoutError
¶
Bases: BaseJobifyError
Raised when job execution exceeds the configured timeout.
Source code in src/jobify/_internal/exceptions.py
RouteAlreadyRegisteredError
¶
Bases: BaseJobifyError
A route with this name has already been registered.