Class: Handinger::Resources::Workers
- Inherits:
-
Object
- Object
- Handinger::Resources::Workers
- Defined in:
- lib/handinger/resources/workers.rb,
lib/handinger/resources/workers/schedules.rb
Defined Under Namespace
Classes: Schedules
Instance Attribute Summary collapse
-
#schedules ⇒ Handinger::Resources::Workers::Schedules
readonly
Manage future and recurring worker tasks.
Instance Method Summary collapse
-
#continue(worker_id, input:, budget: nil, stream: nil, request_options: {}) ⇒ Handinger::Models::Worker
Send another instruction to an existing worker.
-
#create(input:, budget: nil, stream: nil, request_options: {}) ⇒ Handinger::Models::Worker
Create a new agent worker and start it with the supplied instruction.
-
#initialize(client:) ⇒ Workers
constructor
private
A new instance of Workers.
-
#retrieve(worker_id, stream: nil, request_options: {}) ⇒ Handinger::Models::Worker
Retrieve the current worker state.
-
#retrieve_email(worker_id, request_options: {}) ⇒ String
Retrieve the inbound email address for a worker.
-
#retrieve_file(file_path, worker_id:, request_options: {}) ⇒ StringIO
Retrieve a file published from a worker workspace.
-
#stream_updates_streaming(worker_id, request_options: {}) ⇒ Handinger::Internal::Stream<String>
Subscribe to a worker using server-sent events.
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.
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
#schedules ⇒ Handinger::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.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/handinger/resources/workers.rb', line 76 def continue(worker_id, params) parsed, = Handinger::WorkerContinueParams.dump_request(params) @client.request( method: :post, path: ["api/workers/%1$s", worker_id], body: parsed, model: Handinger::Worker, 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.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/handinger/resources/workers.rb', line 22 def create(params) parsed, = Handinger::WorkerCreateParams.dump_request(params) @client.request( method: :post, path: "api/workers", body: parsed, model: Handinger::Worker, 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.
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, = 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: ) end |
#retrieve_email(worker_id, request_options: {}) ⇒ String
Retrieve the inbound email address for a worker.
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/.
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, = 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: ) end |
#stream_updates_streaming(worker_id, request_options: {}) ⇒ Handinger::Internal::Stream<String>
Subscribe to a worker using server-sent events.
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 |