Class: Smplkit::Jobs::JobsClient
- Inherits:
-
Object
- Object
- Smplkit::Jobs::JobsClient
- Defined in:
- lib/smplkit/jobs/client.rb
Overview
The active-record entry point is #new: instantiate a draft, mutate fields, then call Smplkit::Jobs::Job#save. Run history and the cancel / rerun run actions live on #runs.
Reachable as client.jobs (Smplkit::Client) or constructed directly —JobsClient.new resolves credentials from ~/.smplkit / env vars.
Instance Attribute Summary collapse
-
#runs ⇒ RunsClient
readonly
Run history and run actions (
client.jobs.runs).
Class Method Summary collapse
-
.open(*args, **kwargs) ⇒ Object
Construct, yield to the block, and close on exit.
Instance Method Summary collapse
- #_create_job(job) ⇒ Object
-
#_update_job(job) ⇒ Object
Header values come back in plaintext on the GET path, so a fetched job round-trips through this full-replace PUT with its header values intact — no need to re-enter secrets.
-
#close ⇒ Object
The generated ApiClient owns Faraday connections that release on GC; there is no explicit shutdown to call.
-
#delete(id) ⇒ nil
Delete a job by its id.
-
#get(id) ⇒ Smplkit::Jobs::Job
Fetch a single job by id.
-
#initialize(api_key = nil, profile: nil, base_domain: nil, scheme: nil, debug: nil, extra_headers: nil, auth_client: nil) ⇒ JobsClient
constructor
A new instance of JobsClient.
-
#list(enabled: nil, page_number: nil, page_size: nil) ⇒ Array<Smplkit::Jobs::Job>
List jobs for the authenticated account.
-
#new(id, name:, schedule:, configuration:, description: nil, enabled: true, concurrency_policy: "ALLOW") ⇒ Smplkit::Jobs::Job
Construct an unsaved Job bound to this client.
-
#run(id) ⇒ Smplkit::Jobs::Run
Trigger one immediate, manual run of a job, ignoring its schedule.
-
#usage ⇒ Smplkit::Jobs::Usage
Current-period usage counters for the account.
Constructor Details
#initialize(api_key = nil, profile: nil, base_domain: nil, scheme: nil, debug: nil, extra_headers: nil, auth_client: nil) ⇒ JobsClient
Returns a new instance of JobsClient.
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/smplkit/jobs/client.rb', line 130 def initialize(api_key = nil, profile: nil, base_domain: nil, scheme: nil, debug: nil, extra_headers: nil, auth_client: nil) auth = auth_client || Jobs.jobs_transport( api_key: api_key, profile: profile, base_domain: base_domain, scheme: scheme, debug: debug, extra_headers: extra_headers ) @api = SmplkitGeneratedClient::Jobs::JobsApi.new(auth) @runs = RunsClient.new(SmplkitGeneratedClient::Jobs::RunsApi.new(auth)) @usage_api = SmplkitGeneratedClient::Jobs::UsageApi.new(auth) end |
Instance Attribute Details
#runs ⇒ RunsClient (readonly)
Returns Run history and run actions (client.jobs.runs).
117 118 119 |
# File 'lib/smplkit/jobs/client.rb', line 117 def runs @runs end |
Class Method Details
.open(*args, **kwargs) ⇒ Object
Construct, yield to the block, and close on exit.
148 149 150 151 152 153 154 155 |
# File 'lib/smplkit/jobs/client.rb', line 148 def self.open(*args, **kwargs) client = new(*args, **kwargs) begin yield client ensure client.close end end |
Instance Method Details
#_create_job(job) ⇒ Object
247 248 249 250 251 252 |
# File 'lib/smplkit/jobs/client.rb', line 247 def _create_job(job) raise ArgumentError, "Job.id is required on create (caller-supplied key)" if job.id.nil? || job.id.empty? resp = Jobs.call_api { @api.create_job(build_create_body(job)) } Job.from_resource(resp.data, client: self) end |
#_update_job(job) ⇒ Object
Header values come back in plaintext on the GET path, so a fetched job round-trips through this full-replace PUT with its header values intact — no need to re-enter secrets.
260 261 262 263 264 265 |
# File 'lib/smplkit/jobs/client.rb', line 260 def _update_job(job) raise ArgumentError, "cannot update a Job with no id" if job.id.nil? resp = Jobs.call_api { @api.update_job(job.id, build_body(job)) } Job.from_resource(resp.data, client: self) end |
#close ⇒ Object
The generated ApiClient owns Faraday connections that release on GC; there is no explicit shutdown to call.
143 144 145 |
# File 'lib/smplkit/jobs/client.rb', line 143 def close nil end |
#delete(id) ⇒ nil
Delete a job by its id.
217 218 219 220 |
# File 'lib/smplkit/jobs/client.rb', line 217 def delete(id) Jobs.call_api { @api.delete_job(id) } nil end |
#get(id) ⇒ Smplkit::Jobs::Job
Fetch a single job by id. The returned instance is bound to this client, so job.save and job.delete work.
208 209 210 211 |
# File 'lib/smplkit/jobs/client.rb', line 208 def get(id) resp = Jobs.call_api { @api.get_job(id) } Job.from_resource(resp.data, client: self) end |
#list(enabled: nil, page_number: nil, page_size: nil) ⇒ Array<Smplkit::Jobs::Job>
List jobs for the authenticated account.
193 194 195 196 197 198 199 200 201 |
# File 'lib/smplkit/jobs/client.rb', line 193 def list(enabled: nil, page_number: nil, page_size: nil) opts = {} opts[:filter_enabled] = enabled unless enabled.nil? opts[:page_number] = page_number unless page_number.nil? opts[:page_size] = page_size unless page_size.nil? resp = Jobs.call_api { @api.list_jobs(opts) } (resp.data || []).map { |r| Job.from_resource(r, client: self) } end |
#new(id, name:, schedule:, configuration:, description: nil, enabled: true, concurrency_policy: "ALLOW") ⇒ Smplkit::Jobs::Job
Construct an unsaved Smplkit::Jobs::Job bound to this client. Call #save on the returned instance to create it.
173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/smplkit/jobs/client.rb', line 173 def new(id, name:, schedule:, configuration:, description: nil, enabled: true, concurrency_policy: "ALLOW") Job.new( self, id: id, name: name, schedule: schedule, configuration: configuration, description: description, enabled: enabled, concurrency_policy: concurrency_policy ) end |
#run(id) ⇒ Smplkit::Jobs::Run
Trigger one immediate, manual run of a job, ignoring its schedule.
This starts an ad-hoc run right now in addition to any scheduled runs; it does not alter the job’s schedule. To read or act on existing runs, use client.jobs.runs.
231 232 233 234 |
# File 'lib/smplkit/jobs/client.rb', line 231 def run(id) resp = Jobs.call_api { @api.run_job_now(id) } Run.from_resource(resp.data) end |
#usage ⇒ Smplkit::Jobs::Usage
Current-period usage counters for the account.
239 240 241 242 |
# File 'lib/smplkit/jobs/client.rb', line 239 def usage resp = Jobs.call_api { @usage_api.get_usage } Usage.from_resource(resp.data) end |