Class: Smplkit::Management::JobsNamespace
- Inherits:
-
Object
- Object
- Smplkit::Management::JobsNamespace
- Defined in:
- lib/smplkit/management/jobs.rb
Overview
Smpl Jobs management surface — accessed via mgmt.jobs.
Unlike Config/Flags/Logging, Jobs has no live “phone-home” agent — no environment registration, no WebSocket — so its entire surface lives on the management client. Defining a job, triggering a run, and reading run history are all plain request/response calls here:
mgmt.jobs.{new,get,list,delete,run,usage}
mgmt.jobs.runs.{list,get,cancel,rerun}
Job#{save,delete}
The active-record entry point is #new: instantiate a draft, mutate fields, then call Jobs::Job#save. Run history and the cancel / rerun run actions live on #runs.
Instance Attribute Summary collapse
-
#runs ⇒ RunsNamespace
readonly
Run history and run actions (
mgmt.jobs.runs).
Instance Method Summary collapse
- #_create_job(job) ⇒ Object
-
#_update_job(job) ⇒ Object
Header values must be re-supplied as plaintext; the GET path redacts them, so a PUT body containing the redacted placeholder would persist that literal.
-
#delete(id) ⇒ nil
Soft-delete a job.
-
#get(id) ⇒ Smplkit::Jobs::Job
Fetch a single job by id.
-
#initialize(api_client) ⇒ JobsNamespace
constructor
A new instance of JobsNamespace.
-
#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 Jobs::Job bound to this namespace.
-
#run(id) ⇒ Smplkit::Jobs::Run
Trigger one immediate
MANUALrun of the job. -
#usage ⇒ Smplkit::Jobs::Usage
Current-period usage counters for the account.
Constructor Details
#initialize(api_client) ⇒ JobsNamespace
Returns a new instance of JobsNamespace.
23 24 25 26 27 28 29 |
# File 'lib/smplkit/management/jobs.rb', line 23 def initialize(api_client) @api = SmplkitGeneratedClient::Jobs::JobsApi.new(api_client) @runs = RunsNamespace.new( SmplkitGeneratedClient::Jobs::RunsApi.new(api_client) ) @usage_api = SmplkitGeneratedClient::Jobs::UsageApi.new(api_client) end |
Instance Attribute Details
#runs ⇒ RunsNamespace (readonly)
Returns Run history and run actions (mgmt.jobs.runs).
21 22 23 |
# File 'lib/smplkit/management/jobs.rb', line 21 def runs @runs end |
Instance Method Details
#_create_job(job) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/smplkit/management/jobs.rb', line 116 def _create_job(job) raise ArgumentError, "Job.id is required on create (caller-supplied key)" if job.id.nil? || job.id.empty? resp = Smplkit::Jobs.call_api { @api.create_job(build_create_body(job)) } Smplkit::Jobs::Job.from_resource(resp.data, client: self) end |
#_update_job(job) ⇒ Object
Header values must be re-supplied as plaintext; the GET path redacts them, so a PUT body containing the redacted placeholder would persist that literal. Track real header values client-side and round-trip them.
129 130 131 132 133 134 |
# File 'lib/smplkit/management/jobs.rb', line 129 def _update_job(job) raise ArgumentError, "cannot update a Job with no id" if job.id.nil? resp = Smplkit::Jobs.call_api { @api.update_job(job.id, build_body(job)) } Smplkit::Jobs::Job.from_resource(resp.data, client: self) end |
#delete(id) ⇒ nil
Soft-delete a job.
91 92 93 94 |
# File 'lib/smplkit/management/jobs.rb', line 91 def delete(id) Smplkit::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 namespace, so job.save and job.delete work.
82 83 84 85 |
# File 'lib/smplkit/management/jobs.rb', line 82 def get(id) resp = Smplkit::Jobs.call_api { @api.get_job(id) } Smplkit::Jobs::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.
67 68 69 70 71 72 73 74 75 |
# File 'lib/smplkit/management/jobs.rb', line 67 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 = Smplkit::Jobs.call_api { @api.list_jobs(opts) } (resp.data || []).map { |r| Smplkit::Jobs::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 Jobs::Job bound to this namespace. Call #save on the returned instance to create it.
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/smplkit/management/jobs.rb', line 47 def new(id, name:, schedule:, configuration:, description: nil, enabled: true, concurrency_policy: "ALLOW") Smplkit::Jobs::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 the job.
100 101 102 103 |
# File 'lib/smplkit/management/jobs.rb', line 100 def run(id) resp = Smplkit::Jobs.call_api { @api.run_job_now(id) } Smplkit::Jobs::Run.from_resource(resp.data) end |
#usage ⇒ Smplkit::Jobs::Usage
Current-period usage counters for the account.
108 109 110 111 |
# File 'lib/smplkit/management/jobs.rb', line 108 def usage resp = Smplkit::Jobs.call_api { @usage_api.get_usage } Smplkit::Jobs::Usage.from_resource(resp.data) end |