The Job Object¶
Every scheduling call returns a Job handle:
await task.push(...)await task.schedule(...).delay(...)await task.schedule(...).at(...)await task.schedule(...).cron(...)
Use this handle to observe state, wait for completion, read result, or cancel.
-
Track
Inspect
job.id,job.status,job.exec_at,job.cron_expression. -
Await
await job.wait()orresult = await job. -
Control
await job.cancel()for scheduled/queued jobs. -
Status Checks
Helpers like
job.is_done()andjob.is_cron()for quick logic branching.
Quick Example¶
import asyncio
from jobify import Jobify, JobStatus
app = Jobify()
@app.task
def add(x: int, y: int) -> int:
return x + y
async def main() -> None:
async with app:
job = await add.schedule(1, 2).delay(1)
print(job.id, job.status)
await job.wait()
if job.status is JobStatus.SUCCESS:
print(job.result()) # 3
if __name__ == "__main__":
asyncio.run(main())
Job Attributes¶
job.id¶
- Type:
str
Unique identifier for the scheduled job instance.
job.status¶
- Type:
JobStatus
Current state value. Possible statuses:
PENDING: internal initial state before scheduler registration.SCHEDULED: registered and waiting for execution.RUNNING: currently executing.CANCELLED: cancelled by user or lifecycle cleanup.SUCCESS: completed with result.FAILED: completed with failure exception.TIMEOUT: stopped by timeout policy.PERMANENTLY_FAILED: cron job stopped by max-failures policy.
job.exec_at¶
- Type:
datetime
Timezone-aware execution timestamp.
job.cron_expression¶
-
Type:
str | None -
Cron jobs: returns expression string.
- One-shot jobs (
push/at/delay):None.
job.exception¶
- Type:
Exception | None
Holds execution exception for terminal error states (for example FAILED, TIMEOUT).
Interacting with a Job¶
Waiting for completion¶
await job.wait()¶
Waits until the job reaches terminal state. It does not raise task exceptions itself.
job.result()¶
Reads result from a completed job.
Behavior:
- returns value when status is
SUCCESS - raises
JobFailedErrorwhen status isFAILED - raises
JobNotCompletedErrorfor non-ready or non-result states
Awaitable shorthand¶
await job¶
Equivalent pattern:
- wait for completion
- return
job.result()
Useful for batching:
Cancelling a Job¶
await job.cancel()¶
Cancels and unschedules the job handle, including persistence cleanup for durable schedules.
Use this for jobs that are scheduled but no longer needed.
Status helpers¶
job.is_done()¶
Returns True when job reached terminal state, else False.
job.is_cron()¶
Returns True if this handle represents cron schedule execution context.