smplkit 3.0.113 → 3.0.114
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.
- checksums.yaml +4 -4
- data/lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/api/jobs_api.rb +14 -11
- data/lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/api/usage_api.rb +2 -2
- data/lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb +25 -29
- data/lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job_environment.rb +1 -1
- data/lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/usage.rb +2 -2
- data/lib/smplkit/_generated/jobs/spec/api/jobs_api_spec.rb +6 -5
- data/lib/smplkit/_generated/jobs/spec/api/usage_api_spec.rb +1 -1
- data/lib/smplkit/_generated/jobs/spec/models/job_spec.rb +5 -1
- data/lib/smplkit/jobs/client.rb +123 -45
- data/lib/smplkit/jobs/models.rb +95 -36
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ac8fe2c97dbe9e809353ffa9240572f0b8121322dce79d599308dba14bf89654
|
|
4
|
+
data.tar.gz: '04689fee543ee875c6d8b0ba68ed3cbd67242a490bee6ed3dafd5b33e030348e'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1f26e6bec44ef6259a7d384ce5cd80c99eba77116a73bd22c3be814fcf683712a6a8b2fd1774e3a0e76cfe58bf28fc0184edcd91266ce3b453db60dd1a6e7fea
|
|
7
|
+
data.tar.gz: bee0e18d7f5d8f4b9bbe64085da2782888ecd82fff072c92d4f81c4379c27f21dfc82643d26261d7a7c0af809b58d112239ae12e840c11b989331dd22317fd29
|
|
@@ -20,7 +20,7 @@ module SmplkitGeneratedClient::Jobs
|
|
|
20
20
|
@api_client = api_client
|
|
21
21
|
end
|
|
22
22
|
# Create Job
|
|
23
|
-
# Create a job for this account. The caller supplies the job's id as `data.id`. Ids are unique within an account and immutable. A recurring job supplies `environments` to choose where it runs
|
|
23
|
+
# Create a job for this account. The caller supplies the job's id as `data.id`. Ids are unique within an account and immutable. The job's kind follows from its `schedule`: omit the schedule for a permanent **manual** job (triggered on demand), give a cron expression for a **recurring** job, or a datetime / `now` for a **one-off** job. A recurring or manual job supplies `environments` to choose where it runs; a recurring job begins scheduling immediately in each enabled environment. A one-off job is created in the environment named by the `X-Smplkit-Environment` header (implied when the credential is scoped to a single environment); a `now` one-off enqueues its single run immediately.
|
|
24
24
|
# @param job_create_request [JobCreateRequest]
|
|
25
25
|
# @param [Hash] opts the optional parameters
|
|
26
26
|
# @option opts [String] :x_smplkit_environment The environment to operate in. Names the single environment a one-off job is born in (or a manual run executes in). Optional when the credential is scoped to a single environment (which is then implied); required when the credential can reach several environments and the choice is otherwise ambiguous. Ignored for a recurring job, whose environments come from its `environments` map.
|
|
@@ -31,7 +31,7 @@ module SmplkitGeneratedClient::Jobs
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
# Create Job
|
|
34
|
-
# Create a job for this account. The caller supplies the job's id as `data.id`. Ids are unique within an account and immutable. A recurring job supplies `environments` to choose where it runs
|
|
34
|
+
# Create a job for this account. The caller supplies the job's id as `data.id`. Ids are unique within an account and immutable. The job's kind follows from its `schedule`: omit the schedule for a permanent **manual** job (triggered on demand), give a cron expression for a **recurring** job, or a datetime / `now` for a **one-off** job. A recurring or manual job supplies `environments` to choose where it runs; a recurring job begins scheduling immediately in each enabled environment. A one-off job is created in the environment named by the `X-Smplkit-Environment` header (implied when the credential is scoped to a single environment); a `now` one-off enqueues its single run immediately.
|
|
35
35
|
# @param job_create_request [JobCreateRequest]
|
|
36
36
|
# @param [Hash] opts the optional parameters
|
|
37
37
|
# @option opts [String] :x_smplkit_environment The environment to operate in. Names the single environment a one-off job is born in (or a manual run executes in). Optional when the credential is scoped to a single environment (which is then implied); required when the credential can reach several environments and the choice is otherwise ambiguous. Ignored for a recurring job, whose environments come from its `environments` map.
|
|
@@ -215,9 +215,10 @@ module SmplkitGeneratedClient::Jobs
|
|
|
215
215
|
end
|
|
216
216
|
|
|
217
217
|
# List Jobs
|
|
218
|
-
# List this account's jobs. Default sort is `name` ascending. Sort by `name`, `created_at`, or `updated_at`, ascending or descending (prefix `-` for descending). Filter with `filter[recurring]` and `filter[name]` (case-insensitive substring
|
|
218
|
+
# List this account's jobs. Default sort is `name` ascending. Sort by `name`, `created_at`, or `updated_at`, ascending or descending (prefix `-` for descending). By default the list omits transient one-off jobs (request `filter[kind]=one_off` to see them). Filter with `filter[kind]` (`recurring` / `manual` / `one_off`), `filter[scheduled]` (jobs with an upcoming fire in some environment — the feed for an upcoming-runs view, which includes one-offs), and `filter[name]` (case-insensitive substring); filters compose with AND. Each job reports its per-environment enablement and `next_run_at` inside its `environments` map; a scoped caller sees that map narrowed to the environments it may access.
|
|
219
219
|
# @param [Hash] opts the optional parameters
|
|
220
|
-
# @option opts [
|
|
220
|
+
# @option opts [String] :filter_kind Restrict to a single job kind: `recurring`, `manual`, or `one_off`. By default one-off jobs are omitted (they are transient and short-lived); request `filter[kind]=one_off` to list them.
|
|
221
|
+
# @option opts [Boolean] :filter_scheduled When `true`, list only jobs that have an upcoming fire in at least one environment (a recurring job's next occurrence, or a pending future one-off) — the feed for an upcoming-runs view; this includes one-off jobs. When `false`, list only jobs with no upcoming fire.
|
|
221
222
|
# @option opts [String] :filter_name Case-insensitive substring match on the job `name` (matches when the name contains the given text).
|
|
222
223
|
# @option opts [String] :sort Field to sort by. Prefix with `-` for descending order. Default: `name`. Allowed values: `created_at`, `-created_at`, `name`, `-name`, `updated_at`, `-updated_at`. (default to 'name')
|
|
223
224
|
# @option opts [Integer] :page_number 1-based page number to return. Optional; defaults to `1` when omitted. Must be `>= 1` — requests with a smaller value are rejected with a 400 error. (default to 1)
|
|
@@ -230,9 +231,10 @@ module SmplkitGeneratedClient::Jobs
|
|
|
230
231
|
end
|
|
231
232
|
|
|
232
233
|
# List Jobs
|
|
233
|
-
# List this account's jobs. Default sort is `name` ascending. Sort by `name`, `created_at`, or `updated_at`, ascending or descending (prefix `-` for descending). Filter with `filter[recurring]` and `filter[name]` (case-insensitive substring
|
|
234
|
+
# List this account's jobs. Default sort is `name` ascending. Sort by `name`, `created_at`, or `updated_at`, ascending or descending (prefix `-` for descending). By default the list omits transient one-off jobs (request `filter[kind]=one_off` to see them). Filter with `filter[kind]` (`recurring` / `manual` / `one_off`), `filter[scheduled]` (jobs with an upcoming fire in some environment — the feed for an upcoming-runs view, which includes one-offs), and `filter[name]` (case-insensitive substring); filters compose with AND. Each job reports its per-environment enablement and `next_run_at` inside its `environments` map; a scoped caller sees that map narrowed to the environments it may access.
|
|
234
235
|
# @param [Hash] opts the optional parameters
|
|
235
|
-
# @option opts [
|
|
236
|
+
# @option opts [String] :filter_kind Restrict to a single job kind: `recurring`, `manual`, or `one_off`. By default one-off jobs are omitted (they are transient and short-lived); request `filter[kind]=one_off` to list them.
|
|
237
|
+
# @option opts [Boolean] :filter_scheduled When `true`, list only jobs that have an upcoming fire in at least one environment (a recurring job's next occurrence, or a pending future one-off) — the feed for an upcoming-runs view; this includes one-off jobs. When `false`, list only jobs with no upcoming fire.
|
|
236
238
|
# @option opts [String] :filter_name Case-insensitive substring match on the job `name` (matches when the name contains the given text).
|
|
237
239
|
# @option opts [String] :sort Field to sort by. Prefix with `-` for descending order. Default: `name`. Allowed values: `created_at`, `-created_at`, `name`, `-name`, `updated_at`, `-updated_at`. (default to 'name')
|
|
238
240
|
# @option opts [Integer] :page_number 1-based page number to return. Optional; defaults to `1` when omitted. Must be `>= 1` — requests with a smaller value are rejected with a 400 error. (default to 1)
|
|
@@ -252,7 +254,8 @@ module SmplkitGeneratedClient::Jobs
|
|
|
252
254
|
|
|
253
255
|
# query parameters
|
|
254
256
|
query_params = opts[:query_params] || {}
|
|
255
|
-
query_params[:'filter[
|
|
257
|
+
query_params[:'filter[kind]'] = opts[:'filter_kind'] if !opts[:'filter_kind'].nil?
|
|
258
|
+
query_params[:'filter[scheduled]'] = opts[:'filter_scheduled'] if !opts[:'filter_scheduled'].nil?
|
|
256
259
|
query_params[:'filter[name]'] = opts[:'filter_name'] if !opts[:'filter_name'].nil?
|
|
257
260
|
query_params[:'sort'] = opts[:'sort'] if !opts[:'sort'].nil?
|
|
258
261
|
query_params[:'page[number]'] = opts[:'page_number'] if !opts[:'page_number'].nil?
|
|
@@ -294,7 +297,7 @@ module SmplkitGeneratedClient::Jobs
|
|
|
294
297
|
end
|
|
295
298
|
|
|
296
299
|
# Run Job Now
|
|
297
|
-
# Trigger one immediate run of the job (a `MANUAL` run). The job's schedule and enabled state are untouched. The run executes in the environment named by the `X-Smplkit-Environment` header; when the job is enabled in exactly one environment that environment is used, and a single-environment credential implies it. The run executes the job's effective configuration for that environment. It is enqueued and executed by the worker; if the account is over its run allotment the run will fail with reason `QUOTA_EXCEEDED` rather than being rejected here.
|
|
300
|
+
# Trigger one immediate run of the job in a specified environment (a `MANUAL` run). This is the primary execution path for a manual job and is also usable ad hoc for a recurring job (\"run now\"). The job's schedule and enabled state are untouched. The run executes in the environment named by the `X-Smplkit-Environment` header; when the job is enabled in exactly one environment that environment is used, and a single-environment credential implies it. The environment must be one the job is **enabled** in (409 otherwise). The run executes the job's effective configuration for that environment. It is enqueued and executed by the worker; if the account is over its run allotment the run will fail with reason `QUOTA_EXCEEDED` rather than being rejected here.
|
|
298
301
|
# @param job_id [String]
|
|
299
302
|
# @param [Hash] opts the optional parameters
|
|
300
303
|
# @option opts [String] :x_smplkit_environment The environment to operate in. Names the single environment a one-off job is born in (or a manual run executes in). Optional when the credential is scoped to a single environment (which is then implied); required when the credential can reach several environments and the choice is otherwise ambiguous. Ignored for a recurring job, whose environments come from its `environments` map.
|
|
@@ -305,7 +308,7 @@ module SmplkitGeneratedClient::Jobs
|
|
|
305
308
|
end
|
|
306
309
|
|
|
307
310
|
# Run Job Now
|
|
308
|
-
# Trigger one immediate run of the job (a `MANUAL` run). The job's schedule and enabled state are untouched. The run executes in the environment named by the `X-Smplkit-Environment` header; when the job is enabled in exactly one environment that environment is used, and a single-environment credential implies it. The run executes the job's effective configuration for that environment. It is enqueued and executed by the worker; if the account is over its run allotment the run will fail with reason `QUOTA_EXCEEDED` rather than being rejected here.
|
|
311
|
+
# Trigger one immediate run of the job in a specified environment (a `MANUAL` run). This is the primary execution path for a manual job and is also usable ad hoc for a recurring job (\"run now\"). The job's schedule and enabled state are untouched. The run executes in the environment named by the `X-Smplkit-Environment` header; when the job is enabled in exactly one environment that environment is used, and a single-environment credential implies it. The environment must be one the job is **enabled** in (409 otherwise). The run executes the job's effective configuration for that environment. It is enqueued and executed by the worker; if the account is over its run allotment the run will fail with reason `QUOTA_EXCEEDED` rather than being rejected here.
|
|
309
312
|
# @param job_id [String]
|
|
310
313
|
# @param [Hash] opts the optional parameters
|
|
311
314
|
# @option opts [String] :x_smplkit_environment The environment to operate in. Names the single environment a one-off job is born in (or a manual run executes in). Optional when the credential is scoped to a single environment (which is then implied); required when the credential can reach several environments and the choice is otherwise ambiguous. Ignored for a recurring job, whose environments come from its `environments` map.
|
|
@@ -360,7 +363,7 @@ module SmplkitGeneratedClient::Jobs
|
|
|
360
363
|
end
|
|
361
364
|
|
|
362
365
|
# Update Job
|
|
363
|
-
# Replace an existing job. Every writable field is overwritten. Set enablement per environment via the `environments` map (a recurring job), or by recreating a one-off job in the desired environment. Each environment may carry its own cron `schedule` override. Editing
|
|
366
|
+
# Replace an existing job. Every writable field is overwritten. The job's kind is re-derived from the new `schedule` (omit it for a manual job). Set enablement per environment via the `environments` map (a recurring or manual job), or by recreating a one-off job in the desired environment. Each environment may carry its own cron `schedule` override (recurring jobs only). Editing a recurring environment's effective schedule recomputes its next fire time; an edit that leaves it unchanged preserves the existing cadence.
|
|
364
367
|
# @param job_id [String]
|
|
365
368
|
# @param job_request [JobRequest]
|
|
366
369
|
# @param [Hash] opts the optional parameters
|
|
@@ -372,7 +375,7 @@ module SmplkitGeneratedClient::Jobs
|
|
|
372
375
|
end
|
|
373
376
|
|
|
374
377
|
# Update Job
|
|
375
|
-
# Replace an existing job. Every writable field is overwritten. Set enablement per environment via the `environments` map (a recurring job), or by recreating a one-off job in the desired environment. Each environment may carry its own cron `schedule` override. Editing
|
|
378
|
+
# Replace an existing job. Every writable field is overwritten. The job's kind is re-derived from the new `schedule` (omit it for a manual job). Set enablement per environment via the `environments` map (a recurring or manual job), or by recreating a one-off job in the desired environment. Each environment may carry its own cron `schedule` override (recurring jobs only). Editing a recurring environment's effective schedule recomputes its next fire time; an edit that leaves it unchanged preserves the existing cadence.
|
|
376
379
|
# @param job_id [String]
|
|
377
380
|
# @param job_request [JobRequest]
|
|
378
381
|
# @param [Hash] opts the optional parameters
|
|
@@ -20,7 +20,7 @@ module SmplkitGeneratedClient::Jobs
|
|
|
20
20
|
@api_client = api_client
|
|
21
21
|
end
|
|
22
22
|
# Get Usage
|
|
23
|
-
# Report this account's current-period usage against its plan allotments. `runs_used` is the number of runs metered so far this calendar month; `active_jobs` is the number of recurring
|
|
23
|
+
# Report this account's current-period usage against its plan allotments. `runs_used` is the number of runs metered so far this calendar month; `active_jobs` is the number of permanent jobs (recurring + manual), which is what the plan's job limit bounds (one-off jobs do not count).
|
|
24
24
|
# @param [Hash] opts the optional parameters
|
|
25
25
|
# @option opts [String] :filter_period (default to 'current')
|
|
26
26
|
# @return [UsageResponse]
|
|
@@ -30,7 +30,7 @@ module SmplkitGeneratedClient::Jobs
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
# Get Usage
|
|
33
|
-
# Report this account's current-period usage against its plan allotments. `runs_used` is the number of runs metered so far this calendar month; `active_jobs` is the number of recurring
|
|
33
|
+
# Report this account's current-period usage against its plan allotments. `runs_used` is the number of runs metered so far this calendar month; `active_jobs` is the number of permanent jobs (recurring + manual), which is what the plan's job limit bounds (one-off jobs do not count).
|
|
34
34
|
# @param [Hash] opts the optional parameters
|
|
35
35
|
# @option opts [String] :filter_period (default to 'current')
|
|
36
36
|
# @return [Array<(UsageResponse, Integer, Hash)>] UsageResponse data, response status code and response headers
|
|
@@ -14,7 +14,7 @@ require 'date'
|
|
|
14
14
|
require 'time'
|
|
15
15
|
|
|
16
16
|
module SmplkitGeneratedClient::Jobs
|
|
17
|
-
# A
|
|
17
|
+
# A unit of work: an HTTP request, run on a schedule or triggered on demand. The job is the definition; each time it fires the service records a run capturing the request, response, timing, and outcome. A job runs per environment: set `environments[<env>].enabled` to enable it there, and optionally give that environment its own `schedule` or `configuration`. A job's `kind` follows from its `schedule`: a **recurring** (cron) job may be enabled in several environments at once and fires once per enabled environment, each on its own next-fire schedule; a **manual** job (no schedule) is permanent and never auto-fires — it runs only when triggered; a **one-off** (`now` or a future datetime) job runs a single time in the environment it was created in and is then spent.
|
|
18
18
|
class Job < ApiModelBase
|
|
19
19
|
# Human-readable name for the job.
|
|
20
20
|
attr_accessor :name
|
|
@@ -25,20 +25,20 @@ module SmplkitGeneratedClient::Jobs
|
|
|
25
25
|
# Job type. Only `http` is supported today.
|
|
26
26
|
attr_accessor :type
|
|
27
27
|
|
|
28
|
-
# The base schedule every environment inherits unless it overrides it
|
|
28
|
+
# The base schedule every environment inherits unless it overrides it, and the field that determines the job's `kind`. Omit it (or send `null`) to create a permanent **manual** job that never auto-fires and runs only when triggered. Provide a 5-field cron expression evaluated in **UTC** for a **recurring** job, an ISO-8601 datetime for a **one-off** run at that instant, or the literal `now` for a one-off run as soon as possible. A datetime or `now` job disables itself after it fires.
|
|
29
29
|
attr_accessor :schedule
|
|
30
30
|
|
|
31
31
|
# The HTTP request to perform, including method, url, headers, body, and timeout.
|
|
32
32
|
attr_accessor :configuration
|
|
33
33
|
|
|
34
|
-
# Per-environment overrides keyed by environment key (e.g. `production`, `staging`). Each entry sets `enabled` (whether the job
|
|
34
|
+
# Per-environment overrides keyed by environment key (e.g. `production`, `staging`). Each entry sets `enabled` (whether the job is enabled — scheduled, for a recurring job, or triggerable, for a manual job — in that environment), an optional `schedule` override (a cron expression for recurring jobs; omit to inherit the base `schedule`), and an optional `configuration` override (omit to inherit the base `configuration`); it also reports the read-only `next_run_at` for that environment. A job with no entry for an environment is disabled there. For a recurring or manual job, supply this map to choose where it runs. For a one-off job, the environment it is created in is recorded here automatically — name it with the `X-Smplkit-Environment` header. Every referenced environment must exist for the account.
|
|
35
35
|
attr_accessor :environments
|
|
36
36
|
|
|
37
37
|
# How overlapping runs are handled. `ALLOW` (the only value today) permits them.
|
|
38
38
|
attr_accessor :concurrency_policy
|
|
39
39
|
|
|
40
|
-
#
|
|
41
|
-
attr_accessor :
|
|
40
|
+
# How the job runs, derived from its base `schedule`: `recurring` for a cron schedule (fires on a repeating cadence), `manual` for no schedule (never auto-fires; runs only when triggered), or `one_off` for a `now` or datetime schedule (runs a single time, then is spent).
|
|
41
|
+
attr_accessor :kind
|
|
42
42
|
|
|
43
43
|
# When the job was created.
|
|
44
44
|
attr_accessor :created_at
|
|
@@ -84,7 +84,7 @@ module SmplkitGeneratedClient::Jobs
|
|
|
84
84
|
:'configuration' => :'configuration',
|
|
85
85
|
:'environments' => :'environments',
|
|
86
86
|
:'concurrency_policy' => :'concurrency_policy',
|
|
87
|
-
:'
|
|
87
|
+
:'kind' => :'kind',
|
|
88
88
|
:'created_at' => :'created_at',
|
|
89
89
|
:'updated_at' => :'updated_at',
|
|
90
90
|
:'deleted_at' => :'deleted_at',
|
|
@@ -112,7 +112,7 @@ module SmplkitGeneratedClient::Jobs
|
|
|
112
112
|
:'configuration' => :'JobHttpConfiguration',
|
|
113
113
|
:'environments' => :'Hash<String, JobEnvironment>',
|
|
114
114
|
:'concurrency_policy' => :'String',
|
|
115
|
-
:'
|
|
115
|
+
:'kind' => :'String',
|
|
116
116
|
:'created_at' => :'Time',
|
|
117
117
|
:'updated_at' => :'Time',
|
|
118
118
|
:'deleted_at' => :'Time',
|
|
@@ -124,7 +124,8 @@ module SmplkitGeneratedClient::Jobs
|
|
|
124
124
|
def self.openapi_nullable
|
|
125
125
|
Set.new([
|
|
126
126
|
:'description',
|
|
127
|
-
:'
|
|
127
|
+
:'schedule',
|
|
128
|
+
:'kind',
|
|
128
129
|
:'created_at',
|
|
129
130
|
:'updated_at',
|
|
130
131
|
:'deleted_at',
|
|
@@ -166,8 +167,6 @@ module SmplkitGeneratedClient::Jobs
|
|
|
166
167
|
|
|
167
168
|
if attributes.key?(:'schedule')
|
|
168
169
|
self.schedule = attributes[:'schedule']
|
|
169
|
-
else
|
|
170
|
-
self.schedule = nil
|
|
171
170
|
end
|
|
172
171
|
|
|
173
172
|
if attributes.key?(:'configuration')
|
|
@@ -188,8 +187,8 @@ module SmplkitGeneratedClient::Jobs
|
|
|
188
187
|
self.concurrency_policy = 'ALLOW'
|
|
189
188
|
end
|
|
190
189
|
|
|
191
|
-
if attributes.key?(:'
|
|
192
|
-
self.
|
|
190
|
+
if attributes.key?(:'kind')
|
|
191
|
+
self.kind = attributes[:'kind']
|
|
193
192
|
end
|
|
194
193
|
|
|
195
194
|
if attributes.key?(:'created_at')
|
|
@@ -230,10 +229,6 @@ module SmplkitGeneratedClient::Jobs
|
|
|
230
229
|
invalid_properties.push('invalid value for "description", the character length must be smaller than or equal to 2000.')
|
|
231
230
|
end
|
|
232
231
|
|
|
233
|
-
if @schedule.nil?
|
|
234
|
-
invalid_properties.push('invalid value for "schedule", schedule cannot be nil.')
|
|
235
|
-
end
|
|
236
|
-
|
|
237
232
|
if @configuration.nil?
|
|
238
233
|
invalid_properties.push('invalid value for "configuration", configuration cannot be nil.')
|
|
239
234
|
end
|
|
@@ -251,10 +246,11 @@ module SmplkitGeneratedClient::Jobs
|
|
|
251
246
|
return false if !@description.nil? && @description.to_s.length > 2000
|
|
252
247
|
type_validator = EnumAttributeValidator.new('String', ["http"])
|
|
253
248
|
return false unless type_validator.valid?(@type)
|
|
254
|
-
return false if @schedule.nil?
|
|
255
249
|
return false if @configuration.nil?
|
|
256
250
|
concurrency_policy_validator = EnumAttributeValidator.new('String', ["ALLOW"])
|
|
257
251
|
return false unless concurrency_policy_validator.valid?(@concurrency_policy)
|
|
252
|
+
kind_validator = EnumAttributeValidator.new('String', ["recurring", "manual", "one_off"])
|
|
253
|
+
return false unless kind_validator.valid?(@kind)
|
|
258
254
|
true
|
|
259
255
|
end
|
|
260
256
|
|
|
@@ -296,16 +292,6 @@ module SmplkitGeneratedClient::Jobs
|
|
|
296
292
|
@type = type
|
|
297
293
|
end
|
|
298
294
|
|
|
299
|
-
# Custom attribute writer method with validation
|
|
300
|
-
# @param [Object] schedule Value to be assigned
|
|
301
|
-
def schedule=(schedule)
|
|
302
|
-
if schedule.nil?
|
|
303
|
-
fail ArgumentError, 'schedule cannot be nil'
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
@schedule = schedule
|
|
307
|
-
end
|
|
308
|
-
|
|
309
295
|
# Custom attribute writer method with validation
|
|
310
296
|
# @param [Object] configuration Value to be assigned
|
|
311
297
|
def configuration=(configuration)
|
|
@@ -326,6 +312,16 @@ module SmplkitGeneratedClient::Jobs
|
|
|
326
312
|
@concurrency_policy = concurrency_policy
|
|
327
313
|
end
|
|
328
314
|
|
|
315
|
+
# Custom attribute writer method checking allowed values (enum).
|
|
316
|
+
# @param [Object] kind Object to be assigned
|
|
317
|
+
def kind=(kind)
|
|
318
|
+
validator = EnumAttributeValidator.new('String', ["recurring", "manual", "one_off"])
|
|
319
|
+
unless validator.valid?(kind)
|
|
320
|
+
fail ArgumentError, "invalid value for \"kind\", must be one of #{validator.allowable_values}."
|
|
321
|
+
end
|
|
322
|
+
@kind = kind
|
|
323
|
+
end
|
|
324
|
+
|
|
329
325
|
# Checks equality by comparing each attribute.
|
|
330
326
|
# @param [Object] Object to be compared
|
|
331
327
|
def ==(o)
|
|
@@ -338,7 +334,7 @@ module SmplkitGeneratedClient::Jobs
|
|
|
338
334
|
configuration == o.configuration &&
|
|
339
335
|
environments == o.environments &&
|
|
340
336
|
concurrency_policy == o.concurrency_policy &&
|
|
341
|
-
|
|
337
|
+
kind == o.kind &&
|
|
342
338
|
created_at == o.created_at &&
|
|
343
339
|
updated_at == o.updated_at &&
|
|
344
340
|
deleted_at == o.deleted_at &&
|
|
@@ -354,7 +350,7 @@ module SmplkitGeneratedClient::Jobs
|
|
|
354
350
|
# Calculates hash code according to all attributes.
|
|
355
351
|
# @return [Integer] Hash code
|
|
356
352
|
def hash
|
|
357
|
-
[name, description, type, schedule, configuration, environments, concurrency_policy,
|
|
353
|
+
[name, description, type, schedule, configuration, environments, concurrency_policy, kind, created_at, updated_at, deleted_at, version].hash
|
|
358
354
|
end
|
|
359
355
|
|
|
360
356
|
# Builds the object from hash
|
|
@@ -19,7 +19,7 @@ module SmplkitGeneratedClient::Jobs
|
|
|
19
19
|
# Whether the job schedules runs in this environment. A job runs in an environment only via this field; it is disabled in every environment by default.
|
|
20
20
|
attr_accessor :enabled
|
|
21
21
|
|
|
22
|
-
# Per-environment schedule override. Omit to inherit the job's base `schedule`. When present, it must be a 5-field cron expression evaluated in **UTC** (e.g. `0 3 * * *`), and is only allowed on a recurring (cron) job — it varies the cadence within that environment
|
|
22
|
+
# Per-environment schedule override. Omit to inherit the job's base `schedule`. When present, it must be a 5-field cron expression evaluated in **UTC** (e.g. `0 3 * * *`), and is only allowed on a recurring (cron) job — it varies the cadence within that environment. It cannot appear on a manual or one-off job, and cannot change a job's kind.
|
|
23
23
|
attr_accessor :schedule
|
|
24
24
|
|
|
25
25
|
# Per-environment HTTP request override. Omit to inherit the job's base `configuration`. When present, it fully replaces the base configuration for runs in this environment.
|
|
@@ -25,10 +25,10 @@ module SmplkitGeneratedClient::Jobs
|
|
|
25
25
|
# Runs included in the plan this period (`-1` means unlimited).
|
|
26
26
|
attr_accessor :runs_included
|
|
27
27
|
|
|
28
|
-
# Number of recurring
|
|
28
|
+
# Number of permanent jobs (recurring and manual) counted against the plan's job limit.
|
|
29
29
|
attr_accessor :active_jobs
|
|
30
30
|
|
|
31
|
-
# Maximum
|
|
31
|
+
# Maximum permanent jobs the plan allows (`-1` means unlimited).
|
|
32
32
|
attr_accessor :active_jobs_limit
|
|
33
33
|
|
|
34
34
|
# Attribute mapping from ruby-style variable name to JSON key.
|
|
@@ -34,7 +34,7 @@ describe 'JobsApi' do
|
|
|
34
34
|
|
|
35
35
|
# unit tests for create_job
|
|
36
36
|
# Create Job
|
|
37
|
-
# Create a job for this account. The caller supplies the job's id as `data.id`. Ids are unique within an account and immutable. A recurring job supplies `environments` to choose where it runs
|
|
37
|
+
# Create a job for this account. The caller supplies the job's id as `data.id`. Ids are unique within an account and immutable. The job's kind follows from its `schedule`: omit the schedule for a permanent **manual** job (triggered on demand), give a cron expression for a **recurring** job, or a datetime / `now` for a **one-off** job. A recurring or manual job supplies `environments` to choose where it runs; a recurring job begins scheduling immediately in each enabled environment. A one-off job is created in the environment named by the `X-Smplkit-Environment` header (implied when the credential is scoped to a single environment); a `now` one-off enqueues its single run immediately.
|
|
38
38
|
# @param job_create_request
|
|
39
39
|
# @param [Hash] opts the optional parameters
|
|
40
40
|
# @option opts [String] :x_smplkit_environment The environment to operate in. Names the single environment a one-off job is born in (or a manual run executes in). Optional when the credential is scoped to a single environment (which is then implied); required when the credential can reach several environments and the choice is otherwise ambiguous. Ignored for a recurring job, whose environments come from its `environments` map.
|
|
@@ -71,9 +71,10 @@ describe 'JobsApi' do
|
|
|
71
71
|
|
|
72
72
|
# unit tests for list_jobs
|
|
73
73
|
# List Jobs
|
|
74
|
-
# List this account's jobs. Default sort is `name` ascending. Sort by `name`, `created_at`, or `updated_at`, ascending or descending (prefix `-` for descending). Filter with `filter[recurring]` and `filter[name]` (case-insensitive substring
|
|
74
|
+
# List this account's jobs. Default sort is `name` ascending. Sort by `name`, `created_at`, or `updated_at`, ascending or descending (prefix `-` for descending). By default the list omits transient one-off jobs (request `filter[kind]=one_off` to see them). Filter with `filter[kind]` (`recurring` / `manual` / `one_off`), `filter[scheduled]` (jobs with an upcoming fire in some environment — the feed for an upcoming-runs view, which includes one-offs), and `filter[name]` (case-insensitive substring); filters compose with AND. Each job reports its per-environment enablement and `next_run_at` inside its `environments` map; a scoped caller sees that map narrowed to the environments it may access.
|
|
75
75
|
# @param [Hash] opts the optional parameters
|
|
76
|
-
# @option opts [
|
|
76
|
+
# @option opts [String] :filter_kind Restrict to a single job kind: `recurring`, `manual`, or `one_off`. By default one-off jobs are omitted (they are transient and short-lived); request `filter[kind]=one_off` to list them.
|
|
77
|
+
# @option opts [Boolean] :filter_scheduled When `true`, list only jobs that have an upcoming fire in at least one environment (a recurring job's next occurrence, or a pending future one-off) — the feed for an upcoming-runs view; this includes one-off jobs. When `false`, list only jobs with no upcoming fire.
|
|
77
78
|
# @option opts [String] :filter_name Case-insensitive substring match on the job `name` (matches when the name contains the given text).
|
|
78
79
|
# @option opts [String] :sort Field to sort by. Prefix with `-` for descending order. Default: `name`. Allowed values: `created_at`, `-created_at`, `name`, `-name`, `updated_at`, `-updated_at`.
|
|
79
80
|
# @option opts [Integer] :page_number 1-based page number to return. Optional; defaults to `1` when omitted. Must be `>= 1` — requests with a smaller value are rejected with a 400 error.
|
|
@@ -88,7 +89,7 @@ describe 'JobsApi' do
|
|
|
88
89
|
|
|
89
90
|
# unit tests for run_job_now
|
|
90
91
|
# Run Job Now
|
|
91
|
-
# Trigger one immediate run of the job (a `MANUAL` run). The job's schedule and enabled state are untouched. The run executes in the environment named by the `X-Smplkit-Environment` header; when the job is enabled in exactly one environment that environment is used, and a single-environment credential implies it. The run executes the job's effective configuration for that environment. It is enqueued and executed by the worker; if the account is over its run allotment the run will fail with reason `QUOTA_EXCEEDED` rather than being rejected here.
|
|
92
|
+
# Trigger one immediate run of the job in a specified environment (a `MANUAL` run). This is the primary execution path for a manual job and is also usable ad hoc for a recurring job (\"run now\"). The job's schedule and enabled state are untouched. The run executes in the environment named by the `X-Smplkit-Environment` header; when the job is enabled in exactly one environment that environment is used, and a single-environment credential implies it. The environment must be one the job is **enabled** in (409 otherwise). The run executes the job's effective configuration for that environment. It is enqueued and executed by the worker; if the account is over its run allotment the run will fail with reason `QUOTA_EXCEEDED` rather than being rejected here.
|
|
92
93
|
# @param job_id
|
|
93
94
|
# @param [Hash] opts the optional parameters
|
|
94
95
|
# @option opts [String] :x_smplkit_environment The environment to operate in. Names the single environment a one-off job is born in (or a manual run executes in). Optional when the credential is scoped to a single environment (which is then implied); required when the credential can reach several environments and the choice is otherwise ambiguous. Ignored for a recurring job, whose environments come from its `environments` map.
|
|
@@ -101,7 +102,7 @@ describe 'JobsApi' do
|
|
|
101
102
|
|
|
102
103
|
# unit tests for update_job
|
|
103
104
|
# Update Job
|
|
104
|
-
# Replace an existing job. Every writable field is overwritten. Set enablement per environment via the `environments` map (a recurring job), or by recreating a one-off job in the desired environment. Each environment may carry its own cron `schedule` override. Editing
|
|
105
|
+
# Replace an existing job. Every writable field is overwritten. The job's kind is re-derived from the new `schedule` (omit it for a manual job). Set enablement per environment via the `environments` map (a recurring or manual job), or by recreating a one-off job in the desired environment. Each environment may carry its own cron `schedule` override (recurring jobs only). Editing a recurring environment's effective schedule recomputes its next fire time; an edit that leaves it unchanged preserves the existing cadence.
|
|
105
106
|
# @param job_id
|
|
106
107
|
# @param job_request
|
|
107
108
|
# @param [Hash] opts the optional parameters
|
|
@@ -34,7 +34,7 @@ describe 'UsageApi' do
|
|
|
34
34
|
|
|
35
35
|
# unit tests for get_usage
|
|
36
36
|
# Get Usage
|
|
37
|
-
# Report this account's current-period usage against its plan allotments. `runs_used` is the number of runs metered so far this calendar month; `active_jobs` is the number of recurring
|
|
37
|
+
# Report this account's current-period usage against its plan allotments. `runs_used` is the number of runs metered so far this calendar month; `active_jobs` is the number of permanent jobs (recurring + manual), which is what the plan's job limit bounds (one-off jobs do not count).
|
|
38
38
|
# @param [Hash] opts the optional parameters
|
|
39
39
|
# @option opts [String] :filter_period
|
|
40
40
|
# @return [UsageResponse]
|
|
@@ -77,9 +77,13 @@ describe SmplkitGeneratedClient::Jobs::Job do
|
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
describe 'test attribute "
|
|
80
|
+
describe 'test attribute "kind"' do
|
|
81
81
|
it 'should work' do
|
|
82
82
|
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
|
|
83
|
+
# validator = Petstore::EnumTest::EnumAttributeValidator.new('String', ["recurring", "manual", "one_off"])
|
|
84
|
+
# validator.allowable_values.each do |value|
|
|
85
|
+
# expect { instance.kind = value }.not_to raise_error
|
|
86
|
+
# end
|
|
83
87
|
end
|
|
84
88
|
end
|
|
85
89
|
|
data/lib/smplkit/jobs/client.rb
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "time"
|
|
4
|
+
|
|
3
5
|
# The Smpl Jobs client — one unified +JobsClient+.
|
|
4
6
|
#
|
|
5
|
-
# Smpl Jobs
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
7
|
+
# Smpl Jobs runs HTTP calls — on a schedule or on demand — and records their
|
|
8
|
+
# run history. Unlike Config/Flags/Logging it installs no in-process machinery,
|
|
9
|
+
# so it has no runtime/management split: a single +JobsClient+ exposes the full
|
|
10
|
+
# surface and is reachable as +client.jobs+ on +Smplkit::Client+ or constructed
|
|
11
|
+
# directly.
|
|
10
12
|
#
|
|
11
|
-
# client.jobs.{
|
|
13
|
+
# client.jobs.{new_recurring_job,new_manual_job,schedule,get,list,delete,run,usage}
|
|
12
14
|
# client.jobs.runs.{list,get,cancel,rerun}
|
|
13
15
|
# Job#{save,delete,trigger,list_runs}
|
|
14
16
|
# Run#{rerun,cancel}
|
|
15
17
|
#
|
|
16
18
|
# A job is enabled per environment: a recurring (cron) job may be enabled in
|
|
17
|
-
# several environments at once, a
|
|
18
|
-
#
|
|
19
|
-
#
|
|
19
|
+
# several environments at once, a manual job (no schedule) runs only when
|
|
20
|
+
# triggered, and a one-off (+now+ / future datetime) job is born in exactly
|
|
21
|
+
# one. A client-level +environment+ default supplies the one-off birth
|
|
22
|
+
# environment on create, the run-now environment, and the +runs.list+
|
|
20
23
|
# +filter[environment]+ scope.
|
|
21
24
|
#
|
|
22
25
|
# The shared model classes (+Job+, +JobEnvironment+, +Run+, +Usage+,
|
|
@@ -98,7 +101,7 @@ module Smplkit
|
|
|
98
101
|
# one client. Defining a job, triggering a run, and reading run history are
|
|
99
102
|
# all plain request/response calls here:
|
|
100
103
|
#
|
|
101
|
-
# client.jobs.{
|
|
104
|
+
# client.jobs.{new_recurring_job,new_manual_job,schedule,get,list,delete,run,usage}
|
|
102
105
|
# client.jobs.runs.{list,get,cancel,rerun}
|
|
103
106
|
# Job#{save,delete,trigger,list_runs}
|
|
104
107
|
# Run#{rerun,cancel}
|
|
@@ -125,9 +128,10 @@ module Smplkit
|
|
|
125
128
|
Transport.build_api_client(SmplkitGeneratedClient::Jobs, "jobs", tcfg, accept: "application/vnd.api+json")
|
|
126
129
|
end
|
|
127
130
|
|
|
128
|
-
# The active-record entry
|
|
129
|
-
#
|
|
130
|
-
# rerun run actions
|
|
131
|
+
# The active-record entry points are {#new_recurring_job}, {#new_manual_job},
|
|
132
|
+
# and {#schedule}: instantiate a draft, mutate fields, then call
|
|
133
|
+
# {Smplkit::Jobs::Job#save}. Run history and the cancel / rerun run actions
|
|
134
|
+
# live on {#runs}.
|
|
131
135
|
#
|
|
132
136
|
# Reachable as +client.jobs+ (+Smplkit::Client+) or constructed directly —
|
|
133
137
|
# +JobsClient.new+ resolves credentials from +~/.smplkit+ / env vars.
|
|
@@ -179,58 +183,113 @@ module Smplkit
|
|
|
179
183
|
end
|
|
180
184
|
end
|
|
181
185
|
|
|
182
|
-
# Construct an unsaved {Smplkit::Jobs::Job} bound to this client.
|
|
183
|
-
# +#save+ on the returned instance to create it.
|
|
186
|
+
# Construct an unsaved recurring {Smplkit::Jobs::Job} bound to this client.
|
|
187
|
+
# Call +#save+ on the returned instance to create it.
|
|
184
188
|
#
|
|
185
189
|
# @param id [String] Caller-supplied unique identifier for the job. Unique
|
|
186
190
|
# within the account and immutable; the service returns 409 if another
|
|
187
191
|
# live job already uses this id.
|
|
188
192
|
# @param name [String] Human-readable name for the job.
|
|
189
|
-
# @param schedule [String]
|
|
190
|
-
#
|
|
191
|
-
#
|
|
192
|
-
#
|
|
193
|
+
# @param schedule [String] The base cadence — a 5-field cron expression
|
|
194
|
+
# evaluated in UTC (e.g. +"0 2 * * *"+) — that every environment inherits
|
|
195
|
+
# unless it sets its own override.
|
|
196
|
+
# @param configuration [Smplkit::Jobs::HttpConfig] The HTTP request the job
|
|
197
|
+
# sends each time it fires.
|
|
193
198
|
# @param description [String, nil] Optional free-text description.
|
|
194
199
|
# @param environments [Hash{String => Smplkit::Jobs::JobEnvironment, Hash}, nil]
|
|
195
|
-
# Per-environment overrides
|
|
196
|
-
#
|
|
197
|
-
#
|
|
198
|
-
#
|
|
199
|
-
#
|
|
200
|
-
# which is born in +environment+ below.
|
|
200
|
+
# Per-environment overrides keyed by environment key — each a
|
|
201
|
+
# {Smplkit::Jobs::JobEnvironment}, or a plain hash (+{ enabled: true }+,
|
|
202
|
+
# optionally with a +:schedule+ cron override and/or a +:configuration+
|
|
203
|
+
# {Smplkit::Jobs::HttpConfig} override). The job is scheduled only in
|
|
204
|
+
# environments enabled here.
|
|
201
205
|
# @param concurrency_policy [String] How overlapping runs are handled.
|
|
202
206
|
# 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.
|
|
206
207
|
# @return [Smplkit::Jobs::Job]
|
|
207
|
-
def
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
208
|
+
def new_recurring_job(id, name:, schedule:, configuration:, description: nil,
|
|
209
|
+
environments: nil, concurrency_policy: "ALLOW")
|
|
210
|
+
_new_job(
|
|
211
|
+
id, name: name, schedule: schedule, configuration: configuration,
|
|
212
|
+
description: description, environments: environments,
|
|
213
|
+
concurrency_policy: concurrency_policy, environment: nil
|
|
214
|
+
)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# Construct an unsaved manual {Smplkit::Jobs::Job} bound to this client.
|
|
218
|
+
# Call +#save+ on the returned instance to create it.
|
|
219
|
+
#
|
|
220
|
+
# A manual job has no schedule — it never auto-fires and runs only when
|
|
221
|
+
# triggered via {#run} / {Smplkit::Jobs::Job#trigger}.
|
|
222
|
+
#
|
|
223
|
+
# @param id [String] Caller-supplied unique identifier for the job. Unique
|
|
224
|
+
# within the account and immutable; the service returns 409 if another
|
|
225
|
+
# live job already uses this id.
|
|
226
|
+
# @param name [String] Human-readable name for the job.
|
|
227
|
+
# @param configuration [Smplkit::Jobs::HttpConfig] The HTTP request the job
|
|
228
|
+
# sends each time it runs.
|
|
229
|
+
# @param description [String, nil] Optional free-text description.
|
|
230
|
+
# @param environments [Hash{String => Smplkit::Jobs::JobEnvironment, Hash}, nil]
|
|
231
|
+
# Per-environment overrides keyed by environment key — each a
|
|
232
|
+
# {Smplkit::Jobs::JobEnvironment}, or a plain hash (+{ enabled: true }+,
|
|
233
|
+
# optionally with a +:configuration+ {Smplkit::Jobs::HttpConfig}
|
|
234
|
+
# override). The job is triggerable only in environments enabled here.
|
|
235
|
+
# @param concurrency_policy [String] How overlapping runs are handled.
|
|
236
|
+
# Defaults to +"ALLOW"+.
|
|
237
|
+
# @return [Smplkit::Jobs::Job]
|
|
238
|
+
def new_manual_job(id, name:, configuration:, description: nil,
|
|
239
|
+
environments: nil, concurrency_policy: "ALLOW")
|
|
240
|
+
_new_job(
|
|
241
|
+
id, name: name, schedule: nil, configuration: configuration,
|
|
242
|
+
description: description, environments: environments,
|
|
243
|
+
concurrency_policy: concurrency_policy, environment: nil
|
|
244
|
+
)
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
# Construct an unsaved one-off {Smplkit::Jobs::Job} bound to this client.
|
|
248
|
+
# Call +#save+ on the returned instance to create it.
|
|
249
|
+
#
|
|
250
|
+
# A one-off job runs a single time at +schedule+ and is then spent.
|
|
251
|
+
#
|
|
252
|
+
# @param id [String] Caller-supplied unique identifier for the job. Unique
|
|
253
|
+
# within the account and immutable; the service returns 409 if another
|
|
254
|
+
# live job already uses this id.
|
|
255
|
+
# @param name [String] Human-readable name for the job.
|
|
256
|
+
# @param schedule [Time] The instant the single run fires.
|
|
257
|
+
# @param configuration [Smplkit::Jobs::HttpConfig] The HTTP request the job
|
|
258
|
+
# sends when it runs.
|
|
259
|
+
# @param description [String, nil] Optional free-text description.
|
|
260
|
+
# @param concurrency_policy [String] How overlapping runs are handled.
|
|
261
|
+
# Defaults to +"ALLOW"+.
|
|
262
|
+
# @param environment [String, nil] The environment the job is born in.
|
|
263
|
+
# Defaults to the client's configured environment.
|
|
264
|
+
# @return [Smplkit::Jobs::Job]
|
|
265
|
+
def schedule(id, name:, schedule:, configuration:, description: nil,
|
|
266
|
+
concurrency_policy: "ALLOW", environment: nil)
|
|
267
|
+
_new_job(
|
|
268
|
+
id, name: name, schedule: schedule.iso8601, configuration: configuration,
|
|
269
|
+
description: description, environments: nil,
|
|
270
|
+
concurrency_policy: concurrency_policy, environment: environment
|
|
219
271
|
)
|
|
220
272
|
end
|
|
221
273
|
|
|
222
274
|
# List jobs for the authenticated account.
|
|
223
275
|
#
|
|
224
|
-
# @param
|
|
225
|
-
# (+
|
|
276
|
+
# @param kind [String, nil] Filter to a single {Smplkit::Jobs::JobKind}
|
|
277
|
+
# (+JobKind::RECURRING+ / +JobKind::MANUAL+ / +JobKind::ONE_OFF+). +nil+
|
|
278
|
+
# lists recurring and manual jobs; one-off jobs are omitted unless you
|
|
279
|
+
# pass +JobKind::ONE_OFF+.
|
|
280
|
+
# @param scheduled [Boolean, nil] Filter to jobs that have an upcoming fire
|
|
281
|
+
# in some environment (+true+) or none (+false+) — the feed for an
|
|
282
|
+
# upcoming-runs view, which includes one-offs. +nil+ does not filter on
|
|
283
|
+
# scheduling.
|
|
226
284
|
# @param name [String, nil] Filter to jobs whose name contains this text
|
|
227
285
|
# (case-insensitive). +nil+ lists all.
|
|
228
286
|
# @param page_number [Integer, nil] 1-based page number to return.
|
|
229
287
|
# @param page_size [Integer, nil] Items per page.
|
|
230
288
|
# @return [Array<Smplkit::Jobs::Job>]
|
|
231
|
-
def list(
|
|
289
|
+
def list(kind: nil, scheduled: nil, name: nil, page_number: nil, page_size: nil)
|
|
232
290
|
opts = {}
|
|
233
|
-
opts[:
|
|
291
|
+
opts[:filter_kind] = kind unless kind.nil?
|
|
292
|
+
opts[:filter_scheduled] = scheduled unless scheduled.nil?
|
|
234
293
|
opts[:filter_name] = name unless name.nil?
|
|
235
294
|
opts[:page_number] = page_number unless page_number.nil?
|
|
236
295
|
opts[:page_size] = page_size unless page_size.nil?
|
|
@@ -268,7 +327,8 @@ module Smplkit
|
|
|
268
327
|
# @param environment [String, nil] Environment the manual run executes in.
|
|
269
328
|
# Defaults to the client's configured environment; when the job is
|
|
270
329
|
# enabled in exactly one environment that environment is used, and a
|
|
271
|
-
# single-environment credential implies it.
|
|
330
|
+
# single-environment credential implies it. The job must be enabled in
|
|
331
|
+
# the chosen environment.
|
|
272
332
|
# @return [Smplkit::Jobs::Run] The run that was started, with +trigger+
|
|
273
333
|
# set to +MANUAL+.
|
|
274
334
|
def run(id, environment: nil)
|
|
@@ -313,6 +373,24 @@ module Smplkit
|
|
|
313
373
|
|
|
314
374
|
private
|
|
315
375
|
|
|
376
|
+
# Build an unsaved {Smplkit::Jobs::Job} bound to this client. The three
|
|
377
|
+
# public constructors ({#new_recurring_job}, {#new_manual_job}, {#schedule})
|
|
378
|
+
# funnel through here.
|
|
379
|
+
def _new_job(id, name:, schedule:, configuration:, description:,
|
|
380
|
+
environments:, concurrency_policy:, environment:)
|
|
381
|
+
Job.new(
|
|
382
|
+
self,
|
|
383
|
+
id: id,
|
|
384
|
+
name: name,
|
|
385
|
+
schedule: schedule,
|
|
386
|
+
configuration: configuration,
|
|
387
|
+
description: description,
|
|
388
|
+
environments: Jobs.normalize_environments(environments),
|
|
389
|
+
concurrency_policy: concurrency_policy,
|
|
390
|
+
birth_environment: environment.nil? ? @environment : environment
|
|
391
|
+
)
|
|
392
|
+
end
|
|
393
|
+
|
|
316
394
|
# Convert the wrapper +environments+ map to the generated model hash.
|
|
317
395
|
#
|
|
318
396
|
# Each entry's +enabled+ is always written; a per-environment +schedule+
|
data/lib/smplkit/jobs/models.rb
CHANGED
|
@@ -6,15 +6,17 @@ module Smplkit
|
|
|
6
6
|
# Unlike Config/Flags/Logging, Jobs has no live "phone-home" agent — no
|
|
7
7
|
# environment registration, no WebSocket — so its entire surface lives on a
|
|
8
8
|
# single client. A {Job} is an active record: build it with
|
|
9
|
-
# +client.jobs.
|
|
9
|
+
# +client.jobs.new_recurring_job(...)+ / +new_manual_job(...)+ /
|
|
10
|
+
# +schedule(...)+, set fields, and call {Job#save} (create when new,
|
|
10
11
|
# full-replace update when it already exists) or {Job#delete}. Runs are
|
|
11
12
|
# read-only views with +rerun+ / +cancel+ actions; run history lives on
|
|
12
13
|
# +client.jobs.runs+.
|
|
13
14
|
#
|
|
14
15
|
# A job is enabled per environment: a recurring (cron) job may run in several
|
|
15
|
-
# environments at once, a
|
|
16
|
-
#
|
|
17
|
-
#
|
|
16
|
+
# environments at once, a manual job (no schedule) runs only when triggered,
|
|
17
|
+
# and a one-off (+now+ / future datetime) job runs a single time in the
|
|
18
|
+
# environment it was created in. Base {Job#enabled} is a derived roll-up
|
|
19
|
+
# (+true+ when enabled in at least one environment), computed from the
|
|
18
20
|
# per-environment {Job#environments} map.
|
|
19
21
|
module Jobs
|
|
20
22
|
# Wrap a generated-jobs-API call and translate +ApiError+ into the
|
|
@@ -98,6 +100,33 @@ module Smplkit
|
|
|
98
100
|
end
|
|
99
101
|
end
|
|
100
102
|
|
|
103
|
+
# How a job runs, derived from its schedule (read-only).
|
|
104
|
+
#
|
|
105
|
+
# - +MANUAL+: No schedule — never auto-fires; runs only when triggered.
|
|
106
|
+
# - +ONE_OFF+: A +now+ or datetime schedule — runs a single time, then is
|
|
107
|
+
# spent.
|
|
108
|
+
# - +RECURRING+: A cron schedule — fires on a repeating cadence.
|
|
109
|
+
module JobKind
|
|
110
|
+
MANUAL = "manual"
|
|
111
|
+
ONE_OFF = "one_off"
|
|
112
|
+
RECURRING = "recurring"
|
|
113
|
+
|
|
114
|
+
VALUES = [MANUAL, ONE_OFF, RECURRING].freeze
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# What started a run (read-only).
|
|
118
|
+
#
|
|
119
|
+
# - +MANUAL+: A +run+ / +trigger+ call started it on demand.
|
|
120
|
+
# - +RERUN+: It repeats an earlier run.
|
|
121
|
+
# - +SCHEDULE+: The job's schedule fired.
|
|
122
|
+
module RunTrigger
|
|
123
|
+
MANUAL = "MANUAL"
|
|
124
|
+
RERUN = "RERUN"
|
|
125
|
+
SCHEDULE = "SCHEDULE"
|
|
126
|
+
|
|
127
|
+
VALUES = [MANUAL, RERUN, SCHEDULE].freeze
|
|
128
|
+
end
|
|
129
|
+
|
|
101
130
|
# HTTP verb a job uses when it fires.
|
|
102
131
|
#
|
|
103
132
|
# Mirrors the jobs spec's method enum so a job's
|
|
@@ -248,13 +277,14 @@ module Smplkit
|
|
|
248
277
|
|
|
249
278
|
# Per-environment enablement, schedule, and configuration override for a job.
|
|
250
279
|
#
|
|
251
|
-
# A
|
|
252
|
-
#
|
|
253
|
-
#
|
|
280
|
+
# A job runs in a given environment only when that environment has an entry
|
|
281
|
+
# in {Job#environments} with +enabled: true+ (scheduled there for a
|
|
282
|
+
# recurring job, triggerable there for a manual one); an environment with no
|
|
283
|
+
# entry (or +enabled: false+) is disabled there.
|
|
254
284
|
#
|
|
255
285
|
# @!attribute [rw] enabled
|
|
256
|
-
# @return [Boolean] Whether the job
|
|
257
|
-
# +false+.
|
|
286
|
+
# @return [Boolean] Whether the job is enabled in this environment.
|
|
287
|
+
# Defaults to +false+.
|
|
258
288
|
# @!attribute [rw] schedule
|
|
259
289
|
# @return [String, nil] Optional per-environment cron schedule override
|
|
260
290
|
# that varies the cadence in this environment. +nil+ (the default)
|
|
@@ -294,19 +324,22 @@ module Smplkit
|
|
|
294
324
|
end
|
|
295
325
|
end
|
|
296
326
|
|
|
297
|
-
# A
|
|
327
|
+
# A unit of work: an HTTP request, run on a schedule or triggered on demand.
|
|
298
328
|
#
|
|
299
|
-
# Active-record style: instantiate via +client.jobs.
|
|
300
|
-
#
|
|
301
|
-
#
|
|
302
|
-
#
|
|
303
|
-
# values without
|
|
329
|
+
# Active-record style: instantiate via +client.jobs.new_recurring_job(...)+,
|
|
330
|
+
# +new_manual_job(...)+, or +schedule(...)+, mutate fields directly, and call
|
|
331
|
+
# {#save} to persist or {#delete} to remove. Header values in
|
|
332
|
+
# +configuration.headers+ are returned in plaintext on reads, so fetching a
|
|
333
|
+
# job, mutating it, and calling {#save} preserves its header values without
|
|
334
|
+
# re-entering secrets.
|
|
304
335
|
#
|
|
305
|
-
#
|
|
306
|
-
#
|
|
307
|
-
#
|
|
308
|
-
#
|
|
309
|
-
#
|
|
336
|
+
# A job's {#kind} follows from its {#schedule}: a recurring (cron) job, a
|
|
337
|
+
# manual job (no schedule, runs only when triggered), or a one-off (+now+ /
|
|
338
|
+
# datetime) job that runs a single time. Enablement is per environment, set
|
|
339
|
+
# via {#set_enabled} (and read via {#is_enabled}); base {#enabled} is a
|
|
340
|
+
# derived roll-up over {#environments}. The base schedule is
|
|
341
|
+
# environment-agnostic, while each environment may carry its own cron
|
|
342
|
+
# {#set_schedule} override.
|
|
310
343
|
class Job
|
|
311
344
|
# @return [String] Caller-supplied unique identifier for the job (the
|
|
312
345
|
# resource +id+). Unique within the account and immutable; the service
|
|
@@ -335,19 +368,22 @@ module Smplkit
|
|
|
335
368
|
# Every referenced environment must exist and be managed for the account.
|
|
336
369
|
attr_accessor :environments
|
|
337
370
|
|
|
338
|
-
# @return [
|
|
339
|
-
#
|
|
340
|
-
# {
|
|
341
|
-
attr_accessor :
|
|
371
|
+
# @return [String, nil] Read-only. How the job runs, derived from its
|
|
372
|
+
# {#schedule} by the server: one of {JobKind::RECURRING},
|
|
373
|
+
# {JobKind::MANUAL}, or {JobKind::ONE_OFF}. +nil+ on an unsaved instance.
|
|
374
|
+
attr_accessor :kind
|
|
342
375
|
|
|
343
376
|
# @return [String] Job type. Only +"http"+ is supported today.
|
|
344
377
|
attr_accessor :type
|
|
345
378
|
|
|
346
|
-
# @return [String]
|
|
347
|
-
#
|
|
348
|
-
#
|
|
349
|
-
#
|
|
350
|
-
#
|
|
379
|
+
# @return [String, nil] The base schedule every environment inherits, and
|
|
380
|
+
# the field that determines the job's {#kind}: +nil+ (omitted) for a
|
|
381
|
+
# permanent manual job that never auto-fires; a 5-field cron expression
|
|
382
|
+
# evaluated in UTC for a recurring job; an ISO-8601 datetime for a
|
|
383
|
+
# one-off run at that instant; or the literal +"now"+ for a one-off run
|
|
384
|
+
# as soon as possible. A datetime or +"now"+ job disables itself after it
|
|
385
|
+
# fires. The schedule is environment-agnostic — set it with
|
|
386
|
+
# {#set_schedule}.
|
|
351
387
|
attr_accessor :schedule
|
|
352
388
|
|
|
353
389
|
# @return [HttpConfig] The base HTTP request to perform when the job fires.
|
|
@@ -375,12 +411,13 @@ module Smplkit
|
|
|
375
411
|
|
|
376
412
|
# @api private — For a one-off job, the environment it is born in, sent as
|
|
377
413
|
# the +X-Smplkit-Environment+ header by {JobsClient#_create_job}. Ignored
|
|
378
|
-
# for
|
|
414
|
+
# for recurring and manual jobs, whose environments come from
|
|
415
|
+
# {#environments}.
|
|
379
416
|
attr_accessor :birth_environment
|
|
380
417
|
|
|
381
|
-
def initialize(client = nil, id:, name:,
|
|
418
|
+
def initialize(client = nil, id:, name:, configuration:, schedule: nil,
|
|
382
419
|
description: nil, environments: nil,
|
|
383
|
-
|
|
420
|
+
kind: nil, type: "http", concurrency_policy: "ALLOW",
|
|
384
421
|
birth_environment: nil, created_at: nil,
|
|
385
422
|
updated_at: nil, deleted_at: nil, version: nil)
|
|
386
423
|
@client = client
|
|
@@ -388,7 +425,7 @@ module Smplkit
|
|
|
388
425
|
@name = name
|
|
389
426
|
@description = description
|
|
390
427
|
@environments = environments || {}
|
|
391
|
-
@
|
|
428
|
+
@kind = kind
|
|
392
429
|
@type = type
|
|
393
430
|
@schedule = schedule
|
|
394
431
|
@configuration = configuration
|
|
@@ -459,6 +496,27 @@ module Smplkit
|
|
|
459
496
|
override.enabled
|
|
460
497
|
end
|
|
461
498
|
|
|
499
|
+
# Whether this is a recurring (cron-scheduled) job.
|
|
500
|
+
#
|
|
501
|
+
# @return [Boolean]
|
|
502
|
+
def is_recurring
|
|
503
|
+
@kind == JobKind::RECURRING
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
# Whether this is a manual job — no schedule; runs only when triggered.
|
|
507
|
+
#
|
|
508
|
+
# @return [Boolean]
|
|
509
|
+
def is_manual
|
|
510
|
+
@kind == JobKind::MANUAL
|
|
511
|
+
end
|
|
512
|
+
|
|
513
|
+
# Whether this is a one-off job — a single +now+ / datetime run.
|
|
514
|
+
#
|
|
515
|
+
# @return [Boolean]
|
|
516
|
+
def is_one_off
|
|
517
|
+
@kind == JobKind::ONE_OFF
|
|
518
|
+
end
|
|
519
|
+
|
|
462
520
|
# Set the job's configuration — base (+environment+ omitted) or
|
|
463
521
|
# per-environment.
|
|
464
522
|
#
|
|
@@ -572,7 +630,7 @@ module Smplkit
|
|
|
572
630
|
@name = other.name
|
|
573
631
|
@description = other.description
|
|
574
632
|
@environments = other.environments
|
|
575
|
-
@
|
|
633
|
+
@kind = other.kind
|
|
576
634
|
@type = other.type
|
|
577
635
|
@schedule = other.schedule
|
|
578
636
|
@configuration = other.configuration
|
|
@@ -602,7 +660,7 @@ module Smplkit
|
|
|
602
660
|
# The base +enabled+ roll-up is derived from +environments+, not read
|
|
603
661
|
# from the wire — the API no longer carries a top-level +enabled+.
|
|
604
662
|
environments: environments,
|
|
605
|
-
|
|
663
|
+
kind: a.kind,
|
|
606
664
|
type: a.type || "http",
|
|
607
665
|
schedule: a.schedule,
|
|
608
666
|
configuration: HttpConfig.from_wire(a.configuration),
|
|
@@ -633,7 +691,8 @@ module Smplkit
|
|
|
633
691
|
# inherits the firing job-environment; a manual run uses the environment
|
|
634
692
|
# named on the run-now request; a rerun copies its source run's environment.
|
|
635
693
|
# @!attribute [rw] trigger
|
|
636
|
-
# @return [String] Why the run exists
|
|
694
|
+
# @return [String] Why the run exists — a raw string equal to one of the
|
|
695
|
+
# {RunTrigger} constants: +SCHEDULE+, +MANUAL+ (run now), or +RERUN+.
|
|
637
696
|
# @!attribute [rw] rerun_of
|
|
638
697
|
# @return [String, nil] The source run's id; set only when +trigger+ is +RERUN+.
|
|
639
698
|
# @!attribute [rw] scheduled_for
|