The Worker API
Worker module for the cloud task processing system.
This module provides tools for integrating existing worker code with the cloud task processing system. It abstracts away the details of cloud provider integration, allowing any worker to process tasks from cloud-based queues.
- class cloud_tasks.worker.Worker(user_worker_function: Callable[[str, Dict[str, Any], WorkerData], Tuple[bool, str]], *, task_source: str | Path | FCPath | Callable[[], Iterable[Dict[str, Any]]] | None = None, args: Sequence[str] | None = None, argparser: ArgumentParser | None = None)[source]
Bases:
objectWorker class for processing tasks from queues using multiprocessing.
- __init__(user_worker_function: Callable[[str, Dict[str, Any], WorkerData], Tuple[bool, str]], *, task_source: str | Path | FCPath | Callable[[], Iterable[Dict[str, Any]]] | None = None, args: Sequence[str] | None = None, argparser: ArgumentParser | None = None)[source]
Initialize the worker.
- Parameters:
user_worker_function – The function to execute for each task. It will be called with the task_id, task_data dictionary, and Worker object as arguments.
task_source – Optional task source. Can be a filename, a pathlib.Path, a filecache.FCPath, or a function that returns an iterator of tasks. If specified, this will override the command line and environment variable task sources.
args – Optional list of command line arguments (sys.argv[1:]).
argparser – Optional argument parser to use. If provided, the command line arguments used by Worker will be added before arguments are parsed. The resulting argparse.Namespace can be retrieved from the WorkerData structure.
- class cloud_tasks.worker.WorkerData[source]
Bases:
objectClass containing properties that can be safely inherited by child processes.
- property received_shutdown_request: bool
Whether the worker has received a shutdown request. This is for the user hitting Ctrl-C at the terminal or otherwise receiving a SIGINT or SIGTERM signal.
- property received_termination_notice: bool
Whether the worker has received a termination notice. This is for a spot instance or system maintenance.
- args: Namespace | None
argparse.Namespace containing the command line arguments, including any additional arguments specified by the user