Class: Smplkit::Jobs::Job
- Inherits:
-
Object
- Object
- Smplkit::Jobs::Job
- Defined in:
- lib/smplkit/jobs/models.rb
Overview
A scheduled unit of work: an HTTP request run on a schedule.
Active-record style: instantiate via mgmt.jobs.new(…), mutate fields directly, and call #save to persist or #delete to remove. Header values in configuration.headers are returned redacted on reads —re-supply the real values before calling #save; the SDK does not cache them client-side.
Instance Attribute Summary collapse
-
#concurrency_policy ⇒ String
How overlapping runs are handled.
-
#configuration ⇒ HttpConfig
The HTTP request to perform when the job fires.
-
#created_at ⇒ String?
ISO-8601 timestamp of first persist.
-
#deleted_at ⇒ String?
Soft-delete timestamp.
-
#description ⇒ String?
Free-text description.
-
#enabled ⇒ Boolean
Whether the job is scheduling runs.
-
#id ⇒ String
Caller-supplied unique identifier for the job (the resource
id). -
#name ⇒ String
Human-readable name for the job.
-
#next_run_at ⇒ String?
The next scheduled fire time.
-
#schedule ⇒ String
When the job runs: an ISO-8601 datetime (a one-off run), a 5-field cron expression evaluated in UTC (recurring), or the literal “now” (run once, as soon as possible).
-
#type ⇒ String
Job type.
-
#updated_at ⇒ String?
ISO-8601 timestamp of the most recent mutation.
-
#version ⇒ Integer?
Monotonic version counter, bumped on every server-side write.
Class Method Summary collapse
Instance Method Summary collapse
- #_apply(other) ⇒ Object private
-
#delete ⇒ nil
(also: #delete!)
Soft-delete this job on the server.
-
#initialize(client = nil, id:, name:, schedule:, configuration:, description: nil, enabled: true, type: "http", concurrency_policy: "ALLOW", next_run_at: nil, created_at: nil, updated_at: nil, deleted_at: nil, version: nil) ⇒ Job
constructor
A new instance of Job.
-
#save ⇒ self
(also: #save!)
Create this job, or full-replace it if it already exists.
Constructor Details
#initialize(client = nil, id:, name:, schedule:, configuration:, description: nil, enabled: true, type: "http", concurrency_policy: "ALLOW", next_run_at: nil, created_at: nil, updated_at: nil, deleted_at: nil, version: nil) ⇒ Job
Returns a new instance of Job.
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/smplkit/jobs/models.rb', line 224 def initialize(client = nil, id:, name:, schedule:, configuration:, description: nil, enabled: true, type: "http", concurrency_policy: "ALLOW", next_run_at: nil, created_at: nil, updated_at: nil, deleted_at: nil, version: nil) @client = client @id = id @name = name @description = description @enabled = enabled @type = type @schedule = schedule @configuration = configuration @concurrency_policy = concurrency_policy @next_run_at = next_run_at @created_at = created_at @updated_at = updated_at @deleted_at = deleted_at @version = version end |
Instance Attribute Details
#concurrency_policy ⇒ String
Returns How overlapping runs are handled. “ALLOW” (the only value) permits them.
204 205 206 |
# File 'lib/smplkit/jobs/models.rb', line 204 def concurrency_policy @concurrency_policy end |
#configuration ⇒ HttpConfig
Returns The HTTP request to perform when the job fires.
200 201 202 |
# File 'lib/smplkit/jobs/models.rb', line 200 def configuration @configuration end |
#created_at ⇒ String?
Returns ISO-8601 timestamp of first persist. nil for an unsaved instance.
212 213 214 |
# File 'lib/smplkit/jobs/models.rb', line 212 def created_at @created_at end |
#deleted_at ⇒ String?
Returns Soft-delete timestamp. nil for live jobs.
218 219 220 |
# File 'lib/smplkit/jobs/models.rb', line 218 def deleted_at @deleted_at end |
#description ⇒ String?
Returns Free-text description. nil when unset.
184 185 186 |
# File 'lib/smplkit/jobs/models.rb', line 184 def description @description end |
#enabled ⇒ Boolean
Returns Whether the job is scheduling runs. false pauses without deleting.
188 189 190 |
# File 'lib/smplkit/jobs/models.rb', line 188 def enabled @enabled end |
#id ⇒ String
Caller-supplied unique identifier for the job (the resource id). Unique within the account and immutable; the service returns 409 if another live job already uses this id.
178 179 180 |
# File 'lib/smplkit/jobs/models.rb', line 178 def id @id end |
#name ⇒ String
Returns Human-readable name for the job.
181 182 183 |
# File 'lib/smplkit/jobs/models.rb', line 181 def name @name end |
#next_run_at ⇒ String?
Returns The next scheduled fire time. nil once a one-off job has fired.
208 209 210 |
# File 'lib/smplkit/jobs/models.rb', line 208 def next_run_at @next_run_at end |
#schedule ⇒ String
Returns When the job runs: an ISO-8601 datetime (a one-off run), a 5-field cron expression evaluated in UTC (recurring), or the literal “now” (run once, as soon as possible). A datetime or “now” job disables itself after it fires.
197 198 199 |
# File 'lib/smplkit/jobs/models.rb', line 197 def schedule @schedule end |
#type ⇒ String
Returns Job type. Only “http” is supported today.
191 192 193 |
# File 'lib/smplkit/jobs/models.rb', line 191 def type @type end |
#updated_at ⇒ String?
Returns ISO-8601 timestamp of the most recent mutation.
215 216 217 |
# File 'lib/smplkit/jobs/models.rb', line 215 def updated_at @updated_at end |
#version ⇒ Integer?
Returns Monotonic version counter, bumped on every server-side write.
222 223 224 |
# File 'lib/smplkit/jobs/models.rb', line 222 def version @version end |
Class Method Details
.from_resource(resource, client: nil) ⇒ Object
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/smplkit/jobs/models.rb', line 288 def self.from_resource(resource, client: nil) a = resource.attributes new( client, id: resource.id, name: a.name, description: a.description, enabled: a.enabled.nil? || a.enabled, type: a.type || "http", schedule: a.schedule, configuration: HttpConfig.from_wire(a.configuration), concurrency_policy: a.concurrency_policy || "ALLOW", next_run_at: a.next_run_at, created_at: a.created_at, updated_at: a.updated_at, deleted_at: a.deleted_at, version: a.version ) end |
Instance Method Details
#_apply(other) ⇒ Object
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.
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/smplkit/jobs/models.rb', line 272 def _apply(other) @id = other.id @name = other.name @description = other.description @enabled = other.enabled @type = other.type @schedule = other.schedule @configuration = other.configuration @concurrency_policy = other.concurrency_policy @next_run_at = other.next_run_at @created_at = other.created_at @updated_at = other.updated_at @deleted_at = other.deleted_at @version = other.version end |
#delete ⇒ nil Also known as: delete!
Soft-delete this job on the server.
264 265 266 267 268 |
# File 'lib/smplkit/jobs/models.rb', line 264 def delete raise "Job was constructed without a client or id; cannot delete" if @client.nil? || @id.nil? @client.delete(@id) end |
#save ⇒ self Also known as: save!
Create this job, or full-replace it if it already exists.
Upsert behavior is driven by #created_at: a job with no created_at is created (POST); otherwise it’s full-replace updated (PUT). After the call, every field is refreshed from the server response (including newly-assigned created_at, version, next_run_at).
252 253 254 255 256 257 258 |
# File 'lib/smplkit/jobs/models.rb', line 252 def save raise "Job was constructed without a client; cannot save" if @client.nil? updated = @created_at.nil? ? @client._create_job(self) : @client._update_job(self) _apply(updated) self end |