# Schedules ## List worker schedules `workers.schedules.list(strworker_id) -> ScheduleListResponse` **get** `/api/workers/{workerId}/schedules` List scheduled tasks for a worker. ### Parameters - `worker_id: str` ### Returns - `class ScheduleListResponse: …` - `schedules: List[WorkerSchedule]` - `class UnionMember0: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `input: str` - `next_run_at: datetime` - `type: Literal["scheduled"]` - `"scheduled"` - `class UnionMember1: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `delay_in_seconds: int` - `input: str` - `next_run_at: datetime` - `type: Literal["delayed"]` - `"delayed"` - `class UnionMember2: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `cron: str` - `input: str` - `next_run_at: datetime` - `type: Literal["cron"]` - `"cron"` - `class UnionMember3: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `input: str` - `interval_seconds: int` - `next_run_at: datetime` - `type: Literal["interval"]` - `"interval"` - `worker_id: str` ### Example ```python import os from handinger import Handinger client = Handinger( api_key=os.environ.get("HANDINGER_API_KEY"), # This is the default and can be omitted ) schedules = client.workers.schedules.list( "t_org_123_w_01HZY2ZJQ8G7K42W2D7WF6V4GM", ) print(schedules.schedules) ``` #### Response ```json { "schedules": [ { "id": "id", "budget": "low", "input": "input", "nextRunAt": "2019-12-27T18:11:19.117Z", "type": "scheduled" } ], "workerId": "workerId" } ``` ## Create a worker schedule `workers.schedules.create(strworker_id, ScheduleCreateParams**kwargs) -> WorkerSchedule` **post** `/api/workers/{workerId}/schedules` Schedule a worker instruction for a future or recurring run. ### Parameters - `worker_id: str` - `input: str` - `when: When` - `class WhenUnionMember0: …` - `date: Union[str, datetime]` - `type: Literal["scheduled"]` - `"scheduled"` - `class WhenUnionMember1: …` - `delay_in_seconds: int` - `type: Literal["delayed"]` - `"delayed"` - `class WhenUnionMember2: …` - `cron: str` - `type: Literal["cron"]` - `"cron"` - `class WhenUnionMember3: …` - `interval_seconds: int` - `type: Literal["interval"]` - `"interval"` - `budget: Optional[Literal["low", "standard", "high", "unlimited"]]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` ### Returns - `WorkerSchedule` - `class UnionMember0: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `input: str` - `next_run_at: datetime` - `type: Literal["scheduled"]` - `"scheduled"` - `class UnionMember1: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `delay_in_seconds: int` - `input: str` - `next_run_at: datetime` - `type: Literal["delayed"]` - `"delayed"` - `class UnionMember2: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `cron: str` - `input: str` - `next_run_at: datetime` - `type: Literal["cron"]` - `"cron"` - `class UnionMember3: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `input: str` - `interval_seconds: int` - `next_run_at: datetime` - `type: Literal["interval"]` - `"interval"` ### Example ```python import os from datetime import datetime from handinger import Handinger client = Handinger( api_key=os.environ.get("HANDINGER_API_KEY"), # This is the default and can be omitted ) worker_schedule = client.workers.schedules.create( worker_id="t_org_123_w_01HZY2ZJQ8G7K42W2D7WF6V4GM", input="x", when={ "date": datetime.fromisoformat("2019-12-27T18:11:19.117"), "type": "scheduled", }, ) print(worker_schedule) ``` #### Response ```json { "id": "id", "budget": "low", "input": "input", "nextRunAt": "2019-12-27T18:11:19.117Z", "type": "scheduled" } ``` ## Cancel a worker schedule `workers.schedules.cancel(strschedule_id, ScheduleCancelParams**kwargs) -> ScheduleCancelResponse` **delete** `/api/workers/{workerId}/schedules/{scheduleId}` Cancel a scheduled task for a worker. ### Parameters - `worker_id: str` - `schedule_id: str` ### Returns - `class ScheduleCancelResponse: …` - `cancelled: bool` ### Example ```python import os from handinger import Handinger client = Handinger( api_key=os.environ.get("HANDINGER_API_KEY"), # This is the default and can be omitted ) response = client.workers.schedules.cancel( schedule_id="sch_01HZY31W2SZJ8MJ2FQTR3M1K9D", worker_id="t_org_123_w_01HZY2ZJQ8G7K42W2D7WF6V4GM", ) print(response.cancelled) ``` #### Response ```json { "cancelled": true } ``` ## Domain Types ### Worker Schedule - `WorkerSchedule` - `class UnionMember0: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `input: str` - `next_run_at: datetime` - `type: Literal["scheduled"]` - `"scheduled"` - `class UnionMember1: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `delay_in_seconds: int` - `input: str` - `next_run_at: datetime` - `type: Literal["delayed"]` - `"delayed"` - `class UnionMember2: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `cron: str` - `input: str` - `next_run_at: datetime` - `type: Literal["cron"]` - `"cron"` - `class UnionMember3: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `input: str` - `interval_seconds: int` - `next_run_at: datetime` - `type: Literal["interval"]` - `"interval"` ### Schedule List Response - `class ScheduleListResponse: …` - `schedules: List[WorkerSchedule]` - `class UnionMember0: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `input: str` - `next_run_at: datetime` - `type: Literal["scheduled"]` - `"scheduled"` - `class UnionMember1: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `delay_in_seconds: int` - `input: str` - `next_run_at: datetime` - `type: Literal["delayed"]` - `"delayed"` - `class UnionMember2: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `cron: str` - `input: str` - `next_run_at: datetime` - `type: Literal["cron"]` - `"cron"` - `class UnionMember3: …` - `id: str` - `budget: Literal["low", "standard", "high", "unlimited"]` - `"low"` - `"standard"` - `"high"` - `"unlimited"` - `input: str` - `interval_seconds: int` - `next_run_at: datetime` - `type: Literal["interval"]` - `"interval"` - `worker_id: str` ### Schedule Cancel Response - `class ScheduleCancelResponse: …` - `cancelled: bool`