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.
- args: Namespace | None
argparse.Namespace containing the command line arguments, including any additional arguments specified by the user
- simulate_spot_termination_after: float | None
The number of seconds after worker start to simulate a spot termination notice
- simulate_spot_termination_delay: float | None
The number of seconds after a simulated spot termination notice to forcibly kill all running tasks