JobQueueManager¶
Module: flowerpower.job_queue.JobQueueManager
The JobQueueManager
is an abstract base class that defines the interface for job queue operations in FlowerPower. It is responsible for enqueuing, scheduling, and managing jobs.
Initialization¶
init¶
Initializes the JobQueueManager
.
Parameter | Type | Description | Default |
---|---|---|---|
type |
str \| None |
The type of job queue backend (e.g., "rq"). | None |
name |
str \| None |
The name of the scheduler. | None |
base_dir |
str \| None |
The base directory of the project. | None |
backend |
BaseBackend \| None |
A backend instance. | None |
storage_options |
dict \| None |
Storage options for the filesystem. | None |
fs |
AbstractFileSystem \| None |
An fsspec-compatible filesystem instance. | None |
Attributes¶
Attribute | Type | Description |
---|---|---|
is_worker_running |
bool |
Indicates if a worker is currently running. |
is_scheduler_running |
bool |
Indicates if the scheduler is currently running. |
Methods¶
enqueue_pipeline¶
Enqueues a pipeline for immediate execution.
Parameter | Type | Description |
---|---|---|
name |
str |
The name of the pipeline. |
*args |
Any |
Positional arguments for the job. |
**kwargs |
Any |
Keyword arguments for the job. |
Returns: Job
- The enqueued job object.
Raises: ValueError
: If the pipeline name is invalid.
Example¶
schedule_pipeline¶
Schedules a pipeline for future or recurring execution.
Parameter | Type | Description |
---|---|---|
name |
str |
The name of the pipeline. |
*args |
Any |
Positional arguments for the job. |
**kwargs |
Any |
Keyword arguments for the job (e.g., cron_string , interval ). |
Returns: ScheduledJob
- The scheduled job object.
Raises: ValueError
: If the pipeline name is invalid or scheduling parameters are insufficient.
Example¶
start_worker¶
Starts a worker process to process jobs from the queue.
Parameter | Type | Description |
---|---|---|
queue_name |
str \| list[str] \| None |
The name(s) of the queue(s) to listen to. Defaults to all queues. |
**kwargs |
Any |
Additional keyword arguments for the worker. |
Returns: None
Raises: RuntimeError
: If the worker fails to start.
Example¶
stop_worker¶
Stops the currently running worker process.
Returns: None
Raises: RuntimeError
: If stopping the worker fails.
Example¶
start_worker_pool¶
Starts a pool of worker processes.
Parameter | Type | Description |
---|---|---|
num_workers |
int |
The number of worker processes to start. |
queue_name |
str \| list[str] \| None |
The name(s) of the queue(s) for the workers to listen to. Defaults to all queues. |
**kwargs |
Any |
Additional keyword arguments for the worker processes. |
Returns: None
Raises: RuntimeError
: If the worker pool fails to start.
Example¶
stop_worker_pool¶
Stops all worker processes in the pool.
Returns: None
Raises: RuntimeError
: If stopping the worker pool fails.
Example¶
enqueue¶
Enqueues a job for immediate, delayed, or scheduled execution.
Parameter | Type | Description |
---|---|---|
func |
Callable |
The function to execute. |
*args |
Any |
Positional arguments for the function. |
**kwargs |
Any |
Keyword arguments for the function and job (e.g., job_id , timeout ). |
Returns: Job
- The enqueued job object.
Raises: ValueError
: If func
is not callable.
Example¶
enqueue_in¶
Enqueues a job to run after a specified delay.
Parameter | Type | Description |
---|---|---|
delay |
timedelta | int | str |
The delay before execution. Can be a timedelta object, an integer (seconds), or a string (e.g., "1m" for 1 minute). |
func |
Callable |
The function to execute. |
*args |
Any |
Positional arguments for the function. |
**kwargs |
Any |
Keyword arguments for the function and job. |
Returns: Job
- The enqueued job object.
Raises: ValueError
: If delay
is invalid or func
is not callable.
Example¶
enqueue_at¶
Enqueues a job to run at a specific datetime.
Parameter | Type | Description |
---|---|---|
datetime_obj |
datetime |
The datetime to execute the job. |
func |
Callable |
The function to execute. |
*args |
Any |
Positional arguments for the function. |
**kwargs |
Any |
Keyword arguments for the function and job. |
Returns: Job
- The enqueued job object.
Raises: ValueError
: If datetime_obj
is in the past or func
is not callable.
Example¶
add_schedule¶
Schedules a job for repeated or one-time execution.
Parameter | Type | Description |
---|---|---|
id |
str |
A unique identifier for the scheduled job. |
func |
Callable |
The function to execute. |
cron_string |
str | None |
A cron string for recurring schedules (e.g., "0 0 * * *" for daily at midnight). |
interval |
int | None |
Interval in seconds for recurring schedules. |
repeat |
int | None |
Number of times to repeat the job. None for infinite. |
enabled |
bool |
Whether the schedule is active. |
**kwargs |
Any |
Additional keyword arguments for the function and job. |
Returns: ScheduledJob
- The scheduled job object.
Raises: ValueError
: If scheduling parameters are invalid or insufficient.
Example¶
get_job_result¶
Gets the result of a completed job.
Parameter | Type | Description |
---|---|---|
job |
str | Job |
The job ID or Job object. |
delete_result |
bool |
If True , deletes the result after retrieval. |
Returns: Any
- The result of the job execution.
Raises:
JobNotFinishedError
: If the job has not completed yet.JobDoesNotExistError
: If the job ID is not found.
Example¶
get_jobs¶
Gets all jobs from specified queues.
Parameter | Type | Description |
---|---|---|
queue_name |
str | list[str] | None |
The name of the queue(s). Defaults to all queues. |
Returns: list[Job]
- A list of job objects.
Example¶
get_schedules¶
Gets all schedules from the scheduler.
Parameter | Type | Description |
---|---|---|
id |
str | list[str] | None |
The ID(s) of the schedule(s). Defaults to all schedules. |
Returns: list[ScheduledJob]
- A list of scheduled job objects.