smplkit 3.0.110 → 3.0.111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ =begin
2
+ #smplkit Jobs API
3
+
4
+ #Scheduled HTTP job execution API for smplkit.
5
+
6
+ The version of the OpenAPI document: 0.1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.22.0
10
+
11
+ =end
12
+
13
+ require 'spec_helper'
14
+ require 'json'
15
+ require 'date'
16
+
17
+ # Unit tests for SmplkitGeneratedClient::Jobs::JobEnvironment
18
+ # Automatically generated by openapi-generator (https://openapi-generator.tech)
19
+ # Please update as you see appropriate
20
+ describe SmplkitGeneratedClient::Jobs::JobEnvironment do
21
+ #let(:instance) { SmplkitGeneratedClient::Jobs::JobEnvironment.new }
22
+
23
+ describe 'test an instance of JobEnvironment' do
24
+ it 'should create an instance of JobEnvironment' do
25
+ # uncomment below to test the instance creation
26
+ #expect(instance).to be_instance_of(SmplkitGeneratedClient::Jobs::JobEnvironment)
27
+ end
28
+ end
29
+
30
+ describe 'test attribute "enabled"' do
31
+ it 'should work' do
32
+ # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
33
+ end
34
+ end
35
+
36
+ describe 'test attribute "configuration"' do
37
+ it 'should work' do
38
+ # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
39
+ end
40
+ end
41
+
42
+ end
@@ -67,6 +67,12 @@ describe SmplkitGeneratedClient::Jobs::Job do
67
67
  end
68
68
  end
69
69
 
70
+ describe 'test attribute "environments"' do
71
+ it 'should work' do
72
+ # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
73
+ end
74
+ end
75
+
70
76
  describe 'test attribute "concurrency_policy"' do
71
77
  it 'should work' do
72
78
  # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
@@ -39,6 +39,12 @@ describe SmplkitGeneratedClient::Jobs::Run do
39
39
  end
40
40
  end
41
41
 
42
+ describe 'test attribute "environment"' do
43
+ it 'should work' do
44
+ # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
45
+ end
46
+ end
47
+
42
48
  describe 'test attribute "trigger"' do
43
49
  it 'should work' do
44
50
  # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
@@ -10,17 +10,28 @@
10
10
  #
11
11
  # client.jobs.{new,get,list,delete,run,usage}
12
12
  # client.jobs.runs.{list,get,cancel,rerun}
13
- # Job#{save,delete}
13
+ # Job#{save,delete,trigger,list_runs}
14
+ # Run#{rerun,cancel}
14
15
  #
15
- # The shared model classes (+Job+, +Run+, +Usage+, +HttpConfig+) live in
16
- # +lib/smplkit/jobs/models.rb+.
16
+ # A job is enabled per environment: a recurring (cron) job may be enabled in
17
+ # several environments at once, a one-off (+now+ / future datetime) job is born
18
+ # in exactly one. A client-level +environment+ default supplies the one-off
19
+ # birth environment on create, the run-now environment, and the +runs.list+
20
+ # +filter[environment]+ scope.
21
+ #
22
+ # The shared model classes (+Job+, +JobEnvironment+, +Run+, +Usage+,
23
+ # +HttpConfig+) live in +lib/smplkit/jobs/models.rb+.
17
24
  module Smplkit
18
25
  module Jobs
19
26
  # +client.jobs.runs.*+ — read-only run history plus the cancel / rerun run
20
27
  # actions.
21
28
  class RunsClient
22
- def initialize(api)
29
+ # @param api [SmplkitGeneratedClient::Jobs::RunsApi] The generated runs API.
30
+ # @param environment [String, nil] Default environment scoping +#list+'s
31
+ # +filter[environment]+ when no explicit +environments+ are passed.
32
+ def initialize(api, environment: nil)
23
33
  @api = api
34
+ @environment = environment
24
35
  end
25
36
 
26
37
  # List past runs, most recent first. Cursor paginated: pass +page_size+
@@ -29,19 +40,25 @@ module Smplkit
29
40
  #
30
41
  # @param job [String, nil] Return only runs of the job with this id.
31
42
  # +nil+ lists runs across all jobs in the account.
43
+ # @param environments [Array<String>, nil] Restrict to runs stamped with
44
+ # any of these environment keys. +nil+ falls back to the client's
45
+ # configured environment (if any), otherwise covers every environment you
46
+ # can access.
32
47
  # @param page_size [Integer, nil] Maximum number of runs to return in this
33
48
  # page. +nil+ uses the server default.
34
49
  # @param after [String, nil] Opaque cursor from a previous page; returns
35
50
  # the runs that follow it. +nil+ starts from the first page.
36
51
  # @return [Array<Smplkit::Jobs::Run>] The runs in this page.
37
- def list(job: nil, page_size: nil, after: nil)
52
+ def list(job: nil, environments: nil, page_size: nil, after: nil)
38
53
  opts = {}
39
54
  opts[:filter_job] = job unless job.nil?
55
+ filter_environment = Jobs.resolve_environment_filter(environments, @environment)
56
+ opts[:filter_environment] = filter_environment unless filter_environment.nil?
40
57
  opts[:page_size] = page_size unless page_size.nil?
41
58
  opts[:page_after] = after unless after.nil?
42
59
 
43
60
  resp = Jobs.call_api { @api.list_runs(opts) }
44
- (resp.data || []).map { |r| Run.from_resource(r) }
61
+ (resp.data || []).map { |r| Run.from_resource(r, runs: self) }
45
62
  end
46
63
 
47
64
  # Fetch a single run by its id.
@@ -51,7 +68,7 @@ module Smplkit
51
68
  # @raise [Smplkit::NotFoundError] when no run with this id exists.
52
69
  def get(run_id)
53
70
  resp = Jobs.call_api { @api.get_run(run_id) }
54
- Run.from_resource(resp.data)
71
+ Run.from_resource(resp.data, runs: self)
55
72
  end
56
73
 
57
74
  # Cancel a run that has not finished yet.
@@ -60,7 +77,7 @@ module Smplkit
60
77
  # @return [Smplkit::Jobs::Run] The updated run reflecting the cancellation.
61
78
  def cancel(run_id)
62
79
  resp = Jobs.call_api { @api.cancel_run(run_id) }
63
- Run.from_resource(resp.data)
80
+ Run.from_resource(resp.data, runs: self)
64
81
  end
65
82
 
66
83
  # Start a new run that repeats a previous one.
@@ -70,7 +87,7 @@ module Smplkit
70
87
  # source +run_id+.
71
88
  def rerun(run_id)
72
89
  resp = Jobs.call_api { @api.rerun_run(run_id) }
73
- Run.from_resource(resp.data)
90
+ Run.from_resource(resp.data, runs: self)
74
91
  end
75
92
  end
76
93
 
@@ -83,15 +100,17 @@ module Smplkit
83
100
  #
84
101
  # client.jobs.{new,get,list,delete,run,usage}
85
102
  # client.jobs.runs.{list,get,cancel,rerun}
86
- # Job#{save,delete}
103
+ # Job#{save,delete,trigger,list_runs}
104
+ # Run#{rerun,cancel}
87
105
  #
88
106
  # Build a standalone Smpl Jobs transport from resolved config.
89
107
  #
90
108
  # Reuses the config resolver (jobs is account-global and never
91
- # environment-scoped) so a standalone jobs client resolves
92
- # credentials/base-domain from +~/.smplkit+ / env vars / constructor args
93
- # exactly like the top-level clients do. Smpl Jobs is JSON:API, so the
94
- # transport carries the +application/vnd.api+json+ Accept header.
109
+ # environment-scoped at the transport layer) so a standalone jobs client
110
+ # resolves credentials/base-domain from +~/.smplkit+ / env vars /
111
+ # constructor args exactly like the top-level clients do. Smpl Jobs is
112
+ # JSON:API, so the transport carries the +application/vnd.api+json+ Accept
113
+ # header.
95
114
  def self.jobs_transport(api_key:, profile:, base_domain:, scheme:, debug:, extra_headers:)
96
115
  cfg = ConfigResolution.resolve_client_config(
97
116
  profile: profile, api_key: api_key, base_domain: base_domain, scheme: scheme, debug: debug
@@ -124,17 +143,23 @@ module Smplkit
124
143
  # @param scheme [String, nil] URL scheme (default +"https"+).
125
144
  # @param debug [Boolean, nil] Enable SDK debug logging.
126
145
  # @param extra_headers [Hash, nil] Extra headers attached to every request.
146
+ # @param environment [String, nil] Default environment for
147
+ # environment-scoped operations — the environment a one-off job created
148
+ # through this client is born in, the default a manual run executes in,
149
+ # and the default scope for +runs.list+. +nil+ leaves these unset (the
150
+ # credential's permitted environment is implied where unambiguous).
127
151
  # @param auth_client [Object, nil] Internal — a pre-built transport
128
152
  # supplied by a top-level client so the jobs surface shares one
129
153
  # connection pool. Not for direct use.
130
154
  def initialize(api_key = nil, profile: nil, base_domain: nil, scheme: nil,
131
- debug: nil, extra_headers: nil, auth_client: nil)
155
+ debug: nil, extra_headers: nil, environment: nil, auth_client: nil)
132
156
  auth = auth_client || Jobs.jobs_transport(
133
157
  api_key: api_key, profile: profile, base_domain: base_domain,
134
158
  scheme: scheme, debug: debug, extra_headers: extra_headers
135
159
  )
160
+ @environment = environment
136
161
  @api = SmplkitGeneratedClient::Jobs::JobsApi.new(auth)
137
- @runs = RunsClient.new(SmplkitGeneratedClient::Jobs::RunsApi.new(auth))
162
+ @runs = RunsClient.new(SmplkitGeneratedClient::Jobs::RunsApi.new(auth), environment: environment)
138
163
  @usage_api = SmplkitGeneratedClient::Jobs::UsageApi.new(auth)
139
164
  end
140
165
 
@@ -162,16 +187,25 @@ module Smplkit
162
187
  # live job already uses this id.
163
188
  # @param name [String] Human-readable name for the job.
164
189
  # @param schedule [String] An ISO-8601 datetime, a 5-field UTC cron
165
- # expression, or the literal +"now"+.
166
- # @param configuration [Smplkit::Jobs::HttpConfig] The HTTP request the
167
- # job performs.
190
+ # expression, or the literal +"now"+. The schedule is environment-agnostic.
191
+ # @param configuration [Smplkit::Jobs::HttpConfig] The base HTTP request
192
+ # the job performs.
168
193
  # @param description [String, nil] Optional free-text description.
169
- # @param enabled [Boolean] Whether the job schedules runs. Defaults +true+.
194
+ # @param environments [Hash{String => Smplkit::Jobs::JobEnvironment, Hash}, nil]
195
+ # Per-environment overrides for a recurring job, keyed by environment key
196
+ # — each a {Smplkit::Jobs::JobEnvironment}, or a plain hash
197
+ # (+{ enabled: true }+, optionally with a +:configuration+
198
+ # {Smplkit::Jobs::HttpConfig} override). A recurring job fires only in
199
+ # environments enabled here. Ignored for a one-off job, which is born in
200
+ # +environment+ below.
170
201
  # @param concurrency_policy [String] How overlapping runs are handled.
171
202
  # Defaults to +"ALLOW"+.
203
+ # @param environment [String, nil] For a one-off job (+"now"+ / datetime
204
+ # schedule), the environment it is born in. Defaults to the client's
205
+ # configured environment. Ignored for a recurring job.
172
206
  # @return [Smplkit::Jobs::Job]
173
207
  def new(id, name:, schedule:, configuration:, description: nil,
174
- enabled: true, concurrency_policy: "ALLOW")
208
+ environments: nil, concurrency_policy: "ALLOW", environment: nil)
175
209
  Job.new(
176
210
  self,
177
211
  id: id,
@@ -179,14 +213,16 @@ module Smplkit
179
213
  schedule: schedule,
180
214
  configuration: configuration,
181
215
  description: description,
182
- enabled: enabled,
183
- concurrency_policy: concurrency_policy
216
+ environments: Jobs.normalize_environments(environments),
217
+ concurrency_policy: concurrency_policy,
218
+ birth_environment: environment.nil? ? @environment : environment
184
219
  )
185
220
  end
186
221
 
187
222
  # List jobs for the authenticated account.
188
223
  #
189
- # @param enabled [Boolean, nil] Filter to jobs matching this enabled state.
224
+ # @param enabled [Boolean, nil] Filter to jobs matching this enabled state
225
+ # (the server-derived roll-up across environments).
190
226
  # @param page_number [Integer, nil] 1-based page number to return.
191
227
  # @param page_size [Integer, nil] Items per page.
192
228
  # @return [Array<Smplkit::Jobs::Job>]
@@ -226,11 +262,16 @@ module Smplkit
226
262
  # use +client.jobs.runs+.
227
263
  #
228
264
  # @param id [String] Identifier of the job to run.
265
+ # @param environment [String, nil] Environment the manual run executes in.
266
+ # Defaults to the client's configured environment; when the job is
267
+ # enabled in exactly one environment that environment is used, and a
268
+ # single-environment credential implies it.
229
269
  # @return [Smplkit::Jobs::Run] The run that was started, with +trigger+
230
270
  # set to +MANUAL+.
231
- def run(id)
232
- resp = Jobs.call_api { @api.run_job_now(id) }
233
- Run.from_resource(resp.data)
271
+ def run(id, environment: nil)
272
+ env = environment.nil? ? @environment : environment
273
+ resp = Jobs.call_api { @api.run_job_now(id, x_smplkit_environment: env) }
274
+ Run.from_resource(resp.data, runs: @runs)
234
275
  end
235
276
 
236
277
  # Current-period usage counters for the account.
@@ -243,16 +284,19 @@ module Smplkit
243
284
 
244
285
  # @api private — POST a new job. Called by {Smplkit::Jobs::Job#save} on
245
286
  # unsaved instances. The jobs service requires a caller-supplied
246
- # +data.id+ on create and 409s on conflict.
287
+ # +data.id+ on create and 409s on conflict. A one-off job's birth
288
+ # environment travels as the +X-Smplkit-Environment+ header.
247
289
  def _create_job(job)
248
290
  raise ArgumentError, "Job.id is required on create (caller-supplied key)" if job.id.nil? || job.id.empty?
249
291
 
250
- resp = Jobs.call_api { @api.create_job(build_create_body(job)) }
292
+ resp = Jobs.call_api { @api.create_job(build_create_body(job), x_smplkit_environment: job.birth_environment) }
251
293
  Job.from_resource(resp.data, client: self)
252
294
  end
253
295
 
254
296
  # @api private — Full-replace PUT for an existing job. Called by
255
- # {Smplkit::Jobs::Job#save} on instances with +created_at+.
297
+ # {Smplkit::Jobs::Job#save} on instances with +created_at+. The client's
298
+ # configured environment (if any) travels as the +X-Smplkit-Environment+
299
+ # header.
256
300
  #
257
301
  # Header values come back in plaintext on the GET path, so a fetched job
258
302
  # round-trips through this full-replace PUT with its header values intact
@@ -260,22 +304,40 @@ module Smplkit
260
304
  def _update_job(job)
261
305
  raise ArgumentError, "cannot update a Job with no id" if job.id.nil?
262
306
 
263
- resp = Jobs.call_api { @api.update_job(job.id, build_body(job)) }
307
+ resp = Jobs.call_api { @api.update_job(job.id, build_body(job), x_smplkit_environment: @environment) }
264
308
  Job.from_resource(resp.data, client: self)
265
309
  end
266
310
 
267
311
  private
268
312
 
313
+ # Convert the wrapper +environments+ map to the generated model hash.
314
+ #
315
+ # Each entry's +enabled+ is always written; a per-environment
316
+ # +configuration+ override is sent as a full {HttpConfig} payload only when
317
+ # present (omit to inherit the base configuration).
318
+ def environments_to_wire(environments)
319
+ (environments || {}).each_with_object({}) do |(env_key, env), out|
320
+ attrs = { enabled: env.enabled }
321
+ attrs[:configuration] = HttpConfig.to_wire(env.configuration) unless env.configuration.nil?
322
+ out[env_key.to_s] = SmplkitGeneratedClient::Jobs::JobEnvironment.new(attrs)
323
+ end
324
+ end
325
+
269
326
  def build_attrs(job)
270
- SmplkitGeneratedClient::Jobs::Job.new(
327
+ # The base +enabled+ is a read-only, server-derived roll-up; we never
328
+ # send it. Enablement travels entirely through +environments+, which is
329
+ # included only when non-empty.
330
+ attrs = {
271
331
  name: job.name,
272
332
  description: job.description,
273
- enabled: job.enabled,
274
333
  type: job.type,
275
334
  schedule: job.schedule,
276
335
  configuration: HttpConfig.to_wire(job.configuration),
277
336
  concurrency_policy: job.concurrency_policy
278
- )
337
+ }
338
+ environments = job.environments
339
+ attrs[:environments] = environments_to_wire(environments) unless environments.nil? || environments.empty?
340
+ SmplkitGeneratedClient::Jobs::Job.new(attrs)
279
341
  end
280
342
 
281
343
  def build_create_body(job)