Class: Handinger::Resources::Workers::Schedules

Inherits:
Object
  • Object
show all
Defined in:
lib/handinger/resources/workers/schedules.rb

Overview

Manage future and recurring worker tasks.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Schedules

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Schedules.

Parameters:



86
87
88
# File 'lib/handinger/resources/workers/schedules.rb', line 86

def initialize(client:)
  @client = client
end

Instance Method Details

#cancel(schedule_id, worker_id:, request_options: {}) ⇒ Handinger::Models::Workers::ScheduleCancelResponse

Cancel a scheduled task for a worker.

Parameters:

  • schedule_id (String)

    Scheduled task id returned by the create schedule endpoint.

  • worker_id (String)

    Worker id returned by the create worker endpoint.

  • request_options (Handinger::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/handinger/resources/workers/schedules.rb', line 69

def cancel(schedule_id, params)
  parsed, options = Handinger::Workers::ScheduleCancelParams.dump_request(params)
  worker_id =
    parsed.delete(:worker_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["api/workers/%1$s/schedules/%2$s", worker_id, schedule_id],
    model: Handinger::Models::Workers::ScheduleCancelResponse,
    options: options
  )
end

#create(worker_id, input:, when_:, budget: nil, request_options: {}) ⇒ Handinger::Models::Workers::WorkerSchedule::Scheduled, ...

Schedule a worker instruction for a future or recurring run.



25
26
27
28
29
30
31
32
33
34
# File 'lib/handinger/resources/workers/schedules.rb', line 25

def create(worker_id, params)
  parsed, options = Handinger::Workers::ScheduleCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["api/workers/%1$s/schedules", worker_id],
    body: parsed,
    model: Handinger::Workers::WorkerSchedule,
    options: options
  )
end

#list(worker_id, request_options: {}) ⇒ Handinger::Models::Workers::ScheduleListResponse

List scheduled tasks for a worker.

Parameters:

  • worker_id (String)

    Worker id returned by the create worker endpoint.

  • request_options (Handinger::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



47
48
49
50
51
52
53
54
# File 'lib/handinger/resources/workers/schedules.rb', line 47

def list(worker_id, params = {})
  @client.request(
    method: :get,
    path: ["api/workers/%1$s/schedules", worker_id],
    model: Handinger::Models::Workers::ScheduleListResponse,
    options: params[:request_options]
  )
end