Class: SmplkitGeneratedClient::Jobs::Job

Inherits:
ApiModelBase show all
Defined in:
lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb

Overview

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.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.

Defined Under Namespace

Classes: EnumAttributeValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiModelBase

_deserialize, #_to_hash, #to_body, #to_s

Constructor Details

#initialize(attributes = {}) ⇒ Job

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 138

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `SmplkitGeneratedClient::Jobs::Job` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  acceptable_attribute_map = self.class.acceptable_attribute_map
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!acceptable_attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `SmplkitGeneratedClient::Jobs::Job`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'name')
    self.name = attributes[:'name']
  else
    self.name = nil
  end

  if attributes.key?(:'description')
    self.description = attributes[:'description']
  end

  if attributes.key?(:'type')
    self.type = attributes[:'type']
  else
    self.type = 'http'
  end

  if attributes.key?(:'schedule')
    self.schedule = attributes[:'schedule']
  end

  if attributes.key?(:'configuration')
    self.configuration = attributes[:'configuration']
  else
    self.configuration = nil
  end

  if attributes.key?(:'environments')
    if (value = attributes[:'environments']).is_a?(Hash)
      self.environments = value
    end
  end

  if attributes.key?(:'concurrency_policy')
    self.concurrency_policy = attributes[:'concurrency_policy']
  else
    self.concurrency_policy = 'ALLOW'
  end

  if attributes.key?(:'kind')
    self.kind = attributes[:'kind']
  end

  if attributes.key?(:'created_at')
    self.created_at = attributes[:'created_at']
  end

  if attributes.key?(:'updated_at')
    self.updated_at = attributes[:'updated_at']
  end

  if attributes.key?(:'deleted_at')
    self.deleted_at = attributes[:'deleted_at']
  end

  if attributes.key?(:'version')
    self.version = attributes[:'version']
  end
end

Instance Attribute Details

#concurrency_policyObject

How overlapping runs are handled. ‘ALLOW` (the only value today) permits them.



38
39
40
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 38

def concurrency_policy
  @concurrency_policy
end

#configurationObject

The HTTP request to perform, including method, url, headers, body, and timeout.



32
33
34
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 32

def configuration
  @configuration
end

#created_atObject

When the job was created.



44
45
46
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 44

def created_at
  @created_at
end

#deleted_atObject

When the job was deleted. ‘null` for active jobs.



50
51
52
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 50

def deleted_at
  @deleted_at
end

#descriptionObject

Free-text description for the job.



23
24
25
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 23

def description
  @description
end

#environmentsObject

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
36
37
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 35

def environments
  @environments
end

#kindObject

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
42
43
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 41

def kind
  @kind
end

#nameObject

Human-readable name for the job.



20
21
22
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 20

def name
  @name
end

#scheduleObject

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
30
31
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 29

def schedule
  @schedule
end

#typeObject

Job type. Only ‘http` is supported today.



26
27
28
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 26

def type
  @type
end

#updated_atObject

When the job was last modified.



47
48
49
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 47

def updated_at
  @updated_at
end

#versionObject

Monotonic counter incremented on every update, starting at 1.



53
54
55
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 53

def version
  @version
end

Class Method Details

.acceptable_attribute_mapObject

Returns attribute mapping this model knows about



96
97
98
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 96

def self.acceptable_attribute_map
  attribute_map
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



101
102
103
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 101

def self.acceptable_attributes
  acceptable_attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 78

def self.attribute_map
  {
    :'name' => :'name',
    :'description' => :'description',
    :'type' => :'type',
    :'schedule' => :'schedule',
    :'configuration' => :'configuration',
    :'environments' => :'environments',
    :'concurrency_policy' => :'concurrency_policy',
    :'kind' => :'kind',
    :'created_at' => :'created_at',
    :'updated_at' => :'updated_at',
    :'deleted_at' => :'deleted_at',
    :'version' => :'version'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 359

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  openapi_types.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_nullableObject

List of attributes with nullable: true



124
125
126
127
128
129
130
131
132
133
134
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 124

def self.openapi_nullable
  Set.new([
    :'description',
    :'schedule',
    :'kind',
    :'created_at',
    :'updated_at',
    :'deleted_at',
    :'version'
  ])
end

.openapi_typesObject

Attribute type mapping.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 106

def self.openapi_types
  {
    :'name' => :'String',
    :'description' => :'String',
    :'type' => :'String',
    :'schedule' => :'String',
    :'configuration' => :'JobHttpConfiguration',
    :'environments' => :'Hash<String, JobEnvironment>',
    :'concurrency_policy' => :'String',
    :'kind' => :'String',
    :'created_at' => :'Time',
    :'updated_at' => :'Time',
    :'deleted_at' => :'Time',
    :'version' => :'Integer'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 327

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      name == o.name &&
      description == o.description &&
      type == o.type &&
      schedule == o.schedule &&
      configuration == o.configuration &&
      environments == o.environments &&
      concurrency_policy == o.concurrency_policy &&
      kind == o.kind &&
      created_at == o.created_at &&
      updated_at == o.updated_at &&
      deleted_at == o.deleted_at &&
      version == o.version
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


346
347
348
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 346

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



352
353
354
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 352

def hash
  [name, description, type, schedule, configuration, environments, concurrency_policy, kind, created_at, updated_at, deleted_at, version].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 213

def list_invalid_properties
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  invalid_properties = Array.new
  if @name.nil?
    invalid_properties.push('invalid value for "name", name cannot be nil.')
  end

  if @name.to_s.length > 200
    invalid_properties.push('invalid value for "name", the character length must be smaller than or equal to 200.')
  end

  if @name.to_s.length < 1
    invalid_properties.push('invalid value for "name", the character length must be greater than or equal to 1.')
  end

  if !@description.nil? && @description.to_s.length > 2000
    invalid_properties.push('invalid value for "description", the character length must be smaller than or equal to 2000.')
  end

  if @configuration.nil?
    invalid_properties.push('invalid value for "configuration", configuration cannot be nil.')
  end

  invalid_properties
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 381

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/smplkit/_generated/jobs/lib/smplkit_jobs_client/models/job.rb', line 241

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  return false if @name.nil?
  return false if @name.to_s.length > 200
  return false if @name.to_s.length < 1
  return false if !@description.nil? && @description.to_s.length > 2000
  type_validator = EnumAttributeValidator.new('String', ["http"])
  return false unless type_validator.valid?(@type)
  return false if @configuration.nil?
  concurrency_policy_validator = EnumAttributeValidator.new('String', ["ALLOW"])
  return false unless concurrency_policy_validator.valid?(@concurrency_policy)
  kind_validator = EnumAttributeValidator.new('String', ["recurring", "manual", "one_off"])
  return false unless kind_validator.valid?(@kind)
  true
end