Class: Handinger::Resources::Workers

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

Defined Under Namespace

Classes: Schedules

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Workers

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 Workers.

Parameters:



161
162
163
164
# File 'lib/handinger/resources/workers.rb', line 161

def initialize(client:)
  @client = client
  @schedules = Handinger::Resources::Workers::Schedules.new(client: client)
end

Instance Attribute Details

#schedulesHandinger::Resources::Workers::Schedules (readonly)

Manage future and recurring worker tasks.



8
9
10
# File 'lib/handinger/resources/workers.rb', line 8

def schedules
  @schedules
end

Instance Method Details

#continue(worker_id, input:, budget: nil, stream: nil, request_options: {}) ⇒ Handinger::Models::Worker

Send another instruction to an existing worker.

Parameters:

Returns:

See Also:



76
77
78
79
80
81
82
83
84
85
# File 'lib/handinger/resources/workers.rb', line 76

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

#create(input:, budget: nil, stream: nil, request_options: {}) ⇒ Handinger::Models::Worker

Create a new agent worker and start it with the supplied instruction.

Parameters:

Returns:

See Also:



22
23
24
25
26
27
28
29
30
31
# File 'lib/handinger/resources/workers.rb', line 22

def create(params)
  parsed, options = Handinger::WorkerCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "api/workers",
    body: parsed,
    model: Handinger::Worker,
    options: options
  )
end

#retrieve(worker_id, stream: nil, request_options: {}) ⇒ Handinger::Models::Worker

Retrieve the current worker state. Pass stream=true or request text/event-stream to subscribe to updates.

Parameters:

  • worker_id (String)

    Worker id returned by the create worker endpoint.

  • stream (Boolean)

    Return a server-sent event stream instead of JSON.

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

Returns:

See Also:



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

def retrieve(worker_id, params = {})
  parsed, options = Handinger::WorkerRetrieveParams.dump_request(params)
  query = Handinger::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["api/workers/%1$s", worker_id],
    query: query,
    model: Handinger::Worker,
    options: options
  )
end

#retrieve_email(worker_id, request_options: {}) ⇒ String

Retrieve the inbound email address for a worker.

Parameters:

  • worker_id (String)

    Worker id returned by the create worker endpoint.

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

Returns:

  • (String)

See Also:



98
99
100
101
102
103
104
105
# File 'lib/handinger/resources/workers.rb', line 98

def retrieve_email(worker_id, params = {})
  @client.request(
    method: :get,
    path: ["api/workers/%1$s/email", worker_id],
    model: String,
    options: params[:request_options]
  )
end

#retrieve_file(file_path, worker_id:, request_options: {}) ⇒ StringIO

Retrieve a file published from a worker workspace. The runtime route accepts nested paths after /files/.

Parameters:

  • file_path (String)

    Workspace file path after /files. URL-encode slashes for nested paths.

  • worker_id (String)

    Worker id returned by the create worker endpoint.

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

Returns:

  • (StringIO)

See Also:



121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/handinger/resources/workers.rb', line 121

def retrieve_file(file_path, params)
  parsed, options = Handinger::WorkerRetrieveFileParams.dump_request(params)
  worker_id =
    parsed.delete(:worker_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["api/workers/%1$s/files/%2$s", worker_id, file_path],
    headers: {"accept" => "application/octet-stream"},
    model: StringIO,
    options: options
  )
end

#stream_updates_streaming(worker_id, request_options: {}) ⇒ Handinger::Internal::Stream<String>

Subscribe to a worker using server-sent events.

Parameters:

  • worker_id (String)

    Worker id returned by the create worker endpoint.

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

Returns:

See Also:



147
148
149
150
151
152
153
154
155
156
# File 'lib/handinger/resources/workers.rb', line 147

def stream_updates_streaming(worker_id, params = {})
  @client.request(
    method: :get,
    path: ["api/workers/%1$s/stream", worker_id],
    headers: {"accept" => "text/event-stream"},
    stream: Handinger::Internal::Stream,
    model: String,
    options: params[:request_options]
  )
end