Skip to content

API Reference parrot.jobs.manager

github-actions[bot] edited this page Dec 2, 2026 · 2 revisions

parrot.jobs.manager

View source

Job Manager for Asynchronous Job Execution.

Manages async execution of jobs (crews, queued chat commands) with job tracking, status monitoring, and result retrieval.

When a RedisJobStore is provided at construction time the manager mirrors every job mutation to Redis, making jobs durable across server restarts.

Alias Job

Re-exported from parrot.jobs.models.Job.

Class JobManager

Manages asynchronous job execution for crew operations.

Provides:

  • Job creation and tracking
  • Async execution with asyncio.create_task
  • Status monitoring
  • Result retrieval
  • Automatic cleanup of old jobs
  • Optional Redis-backed persistence via RedisJobStore
Parameter Type Default Description
id str 'default' Logical identifier for this manager instance.
cleanup_interval int 3600 Seconds between automatic cleanup sweeps.
job_ttl int 86400 Seconds to keep completed/failed jobs in memory (and Redis).
store Optional[RedisJobStore] None Optional RedisJobStore instance. When supplied every job create/update/delete is also mirrored to Redis so that job state survives server restarts.
persistence_timeout float 0.5

Attributes:

Attribute Type Description
jobs Dict[str, Job]
tasks Dict[str, asyncio.Task]

Method JobManager.start

Start the job manager and periodic cleanup task.

start() -> None

Method JobManager.stop

Stop the job manager and cancel all running tasks.

stop() -> None

Method JobManager.update_metadata

Merge values into a job's metadata and persist the change.

Metadata is the only part of a running job that changes without a status transition, and _persist is otherwise only called on those transitions — so a handler mutating job.metadata directly updates the in-memory object and nothing else. A poll served by another worker, or served after the in-memory entry is gone, then reports the job's state from whenever it last changed status. For a long job that publishes progress, that is the whole point of the field.

update_metadata(job_id: str, **values: Any) -> Optional[Job]

Parameter Type Default Description
job_id str The job to update.
**values Any {} Keys merged into job.metadata.

Returns: Optional[Job] — The updated :class:Job, or None when it is unknown.

Method JobManager.report_progress

Record a progress payload against a job, durably.

report_progress(job_id: str, progress: Any) -> Optional[Job]

Parameter Type Default Description
job_id str The job to update.
progress Any A JSON-serialisable progress value. A Pydantic model is dumped, so callers can pass a typed progress object without the job layer knowing its shape.

Returns: Optional[Job] — The updated :class:Job, or None when it is unknown.

Method JobManager.create_job

Create a new job and register it in memory (and Redis if configured).

create_job(job_id: str, obj_id: str, query: Any, user_id: Optional[str] = None, session_id: Optional[str] = None, execution_mode: Optional[str] = None, *, metadata: Optional[dict[str, Any]] = None) -> Job

Parameter Type Default Description
job_id str Unique identifier for the job.
obj_id str ID of the object/handler that owns this job.
query Any The work payload (prompt, task description, etc.).
user_id Optional[str] None Optional user identifier for tracking.
session_id Optional[str] None Optional session identifier for tracking.
execution_mode Optional[str] None Execution mode label (e.g. 'video_reel').
metadata Optional[dict[str, Any]] None

Returns: Job — The newly created Job.

Method JobManager.execute_job

Schedule a job for async execution.

execute_job(job_id: str, execution_func: Callable[[], Awaitable[Any]]) -> None

Parameter Type Default Description
job_id str ID of the job to execute.
execution_func Callable[[], Awaitable[Any]] Async callable that performs the actual work.

Method JobManager.cancel_job

Cancel an owned live task while retaining its record and reason.

cancel_job(job_id: str, reason: str = 'Job was cancelled') -> bool

Parameter Type Default Description
job_id str
reason str 'Job was cancelled'

Returns: bool

Method JobManager.get_job

Return a job from the in-memory store.

If the job is not found in memory and a Redis store is configured, use get_job_async() instead for a full Redis lookup.

get_job(job_id: str) -> Optional[Job]

Parameter Type Default Description
job_id str Job identifier.

Returns: Optional[Job] — Job if found in memory, None otherwise.

Method JobManager.get_job_async

Return a job from memory or Redis.

Owned records are served from memory. Foreign records are always read afresh from Redis and are never added to the owned map.

get_job_async(job_id: str) -> Optional[Job]

Parameter Type Default Description
job_id str Job identifier.

Returns: Optional[Job] — Job if found, None otherwise.

Method JobManager.list_jobs

List in-memory jobs with optional filtering (newest first).

For a full Redis-backed listing use list_jobs_async().

list_jobs(obj_id: Optional[str] = None, status: Optional[JobStatus] = None, limit: int = 100, user_id: Optional[str] = None) -> list

Parameter Type Default Description
obj_id Optional[str] None Filter by object ID.
status Optional[JobStatus] None Filter by status.
limit int 100 Maximum number of jobs to return.
user_id Optional[str] None

Returns: list — List of Job objects.

Method JobManager.list_jobs_async

List jobs from Redis (if store configured) or memory.

list_jobs_async(obj_id: Optional[str] = None, status: Optional[JobStatus] = None, limit: int = 100, user_id: Optional[str] = None) -> list

Parameter Type Default Description
obj_id Optional[str] None Filter by object ID.
status Optional[JobStatus] None Filter by status.
limit int 100 Maximum number of jobs to return.
user_id Optional[str] None

Returns: list — List of Job objects sorted newest-first.

Method JobManager.delete_job

Delete a job from memory (and Redis if configured).

delete_job(job_id: str) -> bool

Parameter Type Default Description
job_id str Job identifier.

Returns: bool — True if the job existed and was deleted.

Method JobManager.get_stats

Return statistics about the in-memory job queue.

get_stats() -> Dict[str, Any]

Returns: Dict[str, Any] — Dictionary with job counts by status and active task count.

Method JobManager.enqueue

Enqueue a function for async execution (RQ-compatible API).

enqueue(func: Callable, args: tuple = None, kwargs: dict = None, queue: str = 'default', timeout: Optional[int] = None, result_ttl: Optional[int] = None, job_id: Optional[str] = None, **extra_kwargs) -> Job

Parameter Type Default Description
func Callable Function to execute (sync or async).
args tuple None Positional arguments for the function.
kwargs dict None Keyword arguments for the function.
queue str 'default' Queue name label (stored in metadata).
timeout Optional[int] None Execution timeout in seconds (not enforced).
result_ttl Optional[int] None How long to keep results (informational).
job_id Optional[str] None Optional job ID; generated if not provided.
**extra_kwargs {} Ignored additional kwargs.

Returns: Job — The created Job.

Method JobManager.fetch_job

Fetch a job by ID (RQ-compatible API).

fetch_job(job_id: str) -> Optional[Job]

Parameter Type Default Description
job_id str The job identifier.

Returns: Optional[Job] — Job if found in memory, None otherwise.

Alias JobStatus

Re-exported from parrot.jobs.models.JobStatus.

Alias RedisJobStore

Re-exported from parrot.jobs.redis_store.RedisJobStore.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally