Class: ReductoAI::Resources::Jobs
- Inherits:
-
Object
- Object
- ReductoAI::Resources::Jobs
- Includes:
- JobStatus
- Defined in:
- lib/reducto_ai/resources/jobs.rb
Overview
Jobs resource for job management and file upload operations.
Provides methods to list, retrieve, cancel jobs, upload files, and configure webhooks for async job notifications.
Constant Summary
Constants included from JobStatus
Instance Method Summary collapse
-
#cancel(job_id:) ⇒ Hash
Cancels a running async job.
-
#configure_webhook ⇒ String
Configures webhook notifications for async jobs.
-
#initialize(client) ⇒ Jobs
constructor
private
A new instance of Jobs.
-
#list(**options) ⇒ Hash
Lists jobs with optional filtering.
-
#retrieve(job_id:) ⇒ Hash
Retrieves job status and results.
-
#upload(file:, extension: nil) ⇒ Hash
Uploads a local file to Reducto's storage.
-
#version ⇒ Hash
Returns API version information.
- #wait(job_id:, interval: 2, timeout: nil, max_attempts: nil, raise_on_failure: true) ⇒ Object
Methods included from JobStatus
#completed?, #completing?, #failed?, #in_progress?, #normalize_status, #pending?, #terminal?
Constructor Details
#initialize(client) ⇒ Jobs
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 Jobs.
30 31 32 |
# File 'lib/reducto_ai/resources/jobs.rb', line 30 def initialize(client) @client = client end |
Instance Method Details
#cancel(job_id:) ⇒ Hash
Cancels a running async job.
81 82 83 84 85 |
# File 'lib/reducto_ai/resources/jobs.rb', line 81 def cancel(job_id:) validate_job_id!(job_id) @client.request(:post, "/cancel/#{job_id}") end |
#configure_webhook ⇒ String
Configures webhook notifications for async jobs.
161 162 163 164 |
# File 'lib/reducto_ai/resources/jobs.rb', line 161 def configure_webhook response = @client.request(:post, "/configure_webhook") normalize_webhook_portal_url(response) end |
#list(**options) ⇒ Hash
Lists jobs with optional filtering.
62 63 64 65 66 |
# File 'lib/reducto_ai/resources/jobs.rb', line 62 def list(**) params = .compact response = @client.request(:get, "/jobs", params: params) normalize_job_list(response) end |
#retrieve(job_id:) ⇒ Hash
Retrieves job status and results.
Used to poll async jobs until completion. Completed jobs include full results in the response.
111 112 113 114 115 |
# File 'lib/reducto_ai/resources/jobs.rb', line 111 def retrieve(job_id:) validate_job_id!(job_id) @client.request(:get, "/job/#{job_id}") end |
#upload(file:, extension: nil) ⇒ Hash
Uploads a local file to Reducto's storage.
Returns a URL that can be used as input for other API operations. Useful when processing local files instead of publicly accessible URLs.
142 143 144 145 146 147 148 149 150 151 |
# File 'lib/reducto_ai/resources/jobs.rb', line 142 def upload(file:, extension: nil) raise ArgumentError, "file is required" if file.nil? upload_io = build_upload_io(file) body = { file: upload_io } params = {} params[:extension] = extension unless extension.nil? @client.request(:post, "/upload", body: body, params: params) end |
#version ⇒ Hash
Returns API version information.
41 42 43 |
# File 'lib/reducto_ai/resources/jobs.rb', line 41 def version @client.request(:get, "/version") end |
#wait(job_id:, interval: 2, timeout: nil, max_attempts: nil, raise_on_failure: true) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/reducto_ai/resources/jobs.rb', line 166 def wait(job_id:, interval: 2, timeout: nil, max_attempts: nil, raise_on_failure: true) validate_wait_arguments!(interval: interval, timeout: timeout, max_attempts: max_attempts) started_at = monotonic_time attempts = 0 loop do attempts += 1 response = retrieve(job_id: job_id) terminal_response = resolve_terminal_response(job_id, response, raise_on_failure) return terminal_response if terminal_response raise_if_attempt_limit_reached!(job_id, response, attempts, max_attempts) raise_if_timeout_exceeded!(job_id, response, started_at, timeout) sleep(interval) end end |