# Schedules ## List worker schedules `workers.schedules.list(worker_id) -> ScheduleListResponse` **get** `/api/workers/{workerId}/schedules` List scheduled tasks for a worker. ### Parameters - `worker_id: String` ### Returns - `class ScheduleListResponse` - `schedules: Array[WorkerSchedule]` - `class Scheduled` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `input: String` - `next_run_at: Time` - `type: :scheduled` - `:scheduled` - `class Delayed` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `delay_in_seconds: Integer` - `input: String` - `next_run_at: Time` - `type: :delayed` - `:delayed` - `class Cron` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `cron: String` - `input: String` - `next_run_at: Time` - `type: :cron` - `:cron` - `class Interval` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `input: String` - `interval_seconds: Integer` - `next_run_at: Time` - `type: :interval` - `:interval` - `worker_id: String` ### Example ```ruby require "handinger" handinger = Handinger::Client.new(api_key: "My API Key") schedules = handinger.workers.schedules.list("t_org_123_w_01HZY2ZJQ8G7K42W2D7WF6V4GM") puts(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(worker_id, **kwargs) -> WorkerSchedule` **post** `/api/workers/{workerId}/schedules` Schedule a worker instruction for a future or recurring run. ### Parameters - `worker_id: String` - `input: String` - `when_: Scheduled{ date, type} | Delayed{ delay_in_seconds, type} | Cron{ cron, type} | Interval{ interval_seconds, type}` - `class Scheduled` - `date: String` - `type: :scheduled` - `:scheduled` - `class Delayed` - `delay_in_seconds: Integer` - `type: :delayed` - `:delayed` - `class Cron` - `cron: String` - `type: :cron` - `:cron` - `class Interval` - `interval_seconds: Integer` - `type: :interval` - `:interval` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` ### Returns - `WorkerSchedule = Scheduled{ id, budget, input, 2 more} | Delayed{ id, budget, delay_in_seconds, 3 more} | Cron{ id, budget, cron, 3 more} | Interval{ id, budget, input, 3 more}` - `class Scheduled` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `input: String` - `next_run_at: Time` - `type: :scheduled` - `:scheduled` - `class Delayed` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `delay_in_seconds: Integer` - `input: String` - `next_run_at: Time` - `type: :delayed` - `:delayed` - `class Cron` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `cron: String` - `input: String` - `next_run_at: Time` - `type: :cron` - `:cron` - `class Interval` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `input: String` - `interval_seconds: Integer` - `next_run_at: Time` - `type: :interval` - `:interval` ### Example ```ruby require "handinger" handinger = Handinger::Client.new(api_key: "My API Key") worker_schedule = handinger.workers.schedules.create( "t_org_123_w_01HZY2ZJQ8G7K42W2D7WF6V4GM", input: "x", when_: {date: "x", type: :scheduled} ) puts(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(schedule_id, **kwargs) -> ScheduleCancelResponse` **delete** `/api/workers/{workerId}/schedules/{scheduleId}` Cancel a scheduled task for a worker. ### Parameters - `worker_id: String` - `schedule_id: String` ### Returns - `class ScheduleCancelResponse` - `cancelled: bool` ### Example ```ruby require "handinger" handinger = Handinger::Client.new(api_key: "My API Key") response = handinger.workers.schedules.cancel( "sch_01HZY31W2SZJ8MJ2FQTR3M1K9D", worker_id: "t_org_123_w_01HZY2ZJQ8G7K42W2D7WF6V4GM" ) puts(response) ``` #### Response ```json { "cancelled": true } ``` ## Domain Types ### Worker Schedule - `WorkerSchedule = Scheduled{ id, budget, input, 2 more} | Delayed{ id, budget, delay_in_seconds, 3 more} | Cron{ id, budget, cron, 3 more} | Interval{ id, budget, input, 3 more}` - `class Scheduled` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `input: String` - `next_run_at: Time` - `type: :scheduled` - `:scheduled` - `class Delayed` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `delay_in_seconds: Integer` - `input: String` - `next_run_at: Time` - `type: :delayed` - `:delayed` - `class Cron` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `cron: String` - `input: String` - `next_run_at: Time` - `type: :cron` - `:cron` - `class Interval` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `input: String` - `interval_seconds: Integer` - `next_run_at: Time` - `type: :interval` - `:interval` ### Schedule List Response - `class ScheduleListResponse` - `schedules: Array[WorkerSchedule]` - `class Scheduled` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `input: String` - `next_run_at: Time` - `type: :scheduled` - `:scheduled` - `class Delayed` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `delay_in_seconds: Integer` - `input: String` - `next_run_at: Time` - `type: :delayed` - `:delayed` - `class Cron` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `cron: String` - `input: String` - `next_run_at: Time` - `type: :cron` - `:cron` - `class Interval` - `id: String` - `budget: :low | :standard | :high | :unlimited` - `:low` - `:standard` - `:high` - `:unlimited` - `input: String` - `interval_seconds: Integer` - `next_run_at: Time` - `type: :interval` - `:interval` - `worker_id: String` ### Schedule Cancel Response - `class ScheduleCancelResponse` - `cancelled: bool`