Class: Smplkit::Jobs::RetryPoliciesClient

Inherits:
Object
  • Object
show all
Defined in:
lib/smplkit/jobs/client.rb

Overview

client.jobs.retry_policies.* — manage reusable, account-global retry policies.

A RetryPolicy is an active record: build one with #new, set fields, and call #save; then reference it from a job’s retry_policy — base: job.retry_policy = policy; per-environment: job.environment(env).retry_policy = policy. Retry policies are account-global — never environment-scoped.

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ RetryPoliciesClient

Returns a new instance of RetryPoliciesClient.

Parameters:



123
124
125
# File 'lib/smplkit/jobs/client.rb', line 123

def initialize(api)
  @api = api
end

Instance Method Details

#_create_retry_policy(policy) ⇒ Object



211
212
213
214
215
216
217
218
# File 'lib/smplkit/jobs/client.rb', line 211

def _create_retry_policy(policy)
  if policy.id.nil? || policy.id.empty?
    raise ArgumentError, "RetryPolicy.id is required on create (caller-supplied key)"
  end

  resp = Jobs.call_api { @api.create_retry_policy(build_create_body(policy)) }
  RetryPolicy.from_resource(resp.data, client: self)
end

#_update_retry_policy(policy) ⇒ Object

Raises:

  • (ArgumentError)


222
223
224
225
226
227
# File 'lib/smplkit/jobs/client.rb', line 222

def _update_retry_policy(policy)
  raise ArgumentError, "cannot update a RetryPolicy with no id" if policy.id.nil?

  resp = Jobs.call_api { @api.update_retry_policy(policy.id, build_body(policy)) }
  RetryPolicy.from_resource(resp.data, client: self)
end

#delete(id) ⇒ nil

Delete a retry policy by its id.

Parameters:

  • id (String)

    Identifier of the policy to delete.

Returns:

  • (nil)


203
204
205
206
# File 'lib/smplkit/jobs/client.rb', line 203

def delete(id)
  Jobs.call_api { @api.delete_retry_policy(id) }
  nil
end

#get(id) ⇒ Smplkit::Jobs::RetryPolicy

Fetch a single retry policy by its id.

Parameters:

  • id (String)

    Identifier of the policy to fetch.

Returns:

Raises:



194
195
196
197
# File 'lib/smplkit/jobs/client.rb', line 194

def get(id)
  resp = Jobs.call_api { @api.get_retry_policy(id) }
  RetryPolicy.from_resource(resp.data, client: self)
end

#list(name: nil, page_number: nil, page_size: nil) ⇒ Array<Smplkit::Jobs::RetryPolicy>

List retry policies in the account.

Parameters:

  • name (String, nil) (defaults to: nil)

    Return only policies whose name contains this text (case-insensitive). nil lists all.

  • page_number (Integer, nil) (defaults to: nil)

    1-based page to return. nil returns the first page.

  • page_size (Integer, nil) (defaults to: nil)

    Maximum number of policies to return in this page. nil uses the server default.

Returns:



179
180
181
182
183
184
185
186
187
# File 'lib/smplkit/jobs/client.rb', line 179

def list(name: nil, page_number: nil, page_size: nil)
  opts = {}
  opts[:filter_name] = name unless name.nil?
  opts[:page_number] = page_number unless page_number.nil?
  opts[:page_size] = page_size unless page_size.nil?

  resp = Jobs.call_api { @api.list_retry_policies(opts) }
  (resp.data || []).map { |r| RetryPolicy.from_resource(r, client: self) }
end

#new(id, name:, max_retries:, backoff:, delay_seconds:, max_delay_seconds: nil, retry_on_timeout: false, retry_on_connection_error: false, retry_statuses: nil, retry_statuses_except: nil) ⇒ Smplkit::Jobs::RetryPolicy

Construct an unsaved Smplkit::Jobs::RetryPolicy bound to this client. Call #save on the returned instance to create it.

Parameters:

  • id (String)

    Caller-supplied unique identifier for the policy. Unique within the account and immutable; the service returns 409 if another live policy already uses this id.

  • name (String)

    Human-readable name for the policy.

  • max_retries (Integer)

    How many times a failed run is retried after the initial attempt — 3 means up to 4 attempts total. 0 disables retries. Maximum 10.

  • backoff (String)

    How the wait between retries grows; one of Backoff.

  • delay_seconds (Integer)

    The wait before a retry, in seconds — the constant wait for Backoff::FIXED, or the base that doubles each retry for Backoff::EXPONENTIAL.

  • max_delay_seconds (Integer, nil) (defaults to: nil)

    Ceiling on the wait between retries, for Backoff::EXPONENTIAL backoff only. nil (the default) leaves it uncapped; omit it for Backoff::FIXED.

  • retry_on_timeout (Boolean) (defaults to: false)

    Retry a run that timed out. Defaults to false.

  • retry_on_connection_error (Boolean) (defaults to: false)

    Retry a run whose destination could not be reached. Defaults to false.

  • retry_statuses (Array<String>, nil) (defaults to: nil)

    Allowlist of response-status patterns to retry on a non-success response. Each element is an exact 3-digit code (e.g. “429”) or a class token (+“1xx”+ … “5xx”). nil (the default) retries no statuses.

  • retry_statuses_except (Array<String>, nil) (defaults to: nil)

    Patterns subtracted from retry_statuses, using the same syntax; except wins on overlap. nil (the default) subtracts nothing.

Returns:



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/smplkit/jobs/client.rb', line 157

def new(id, name:, max_retries:, backoff:, delay_seconds:, max_delay_seconds: nil,
        retry_on_timeout: false, retry_on_connection_error: false,
        retry_statuses: nil, retry_statuses_except: nil)
  RetryPolicy.new(
    self,
    id: id, name: name, max_retries: max_retries, backoff: backoff,
    delay_seconds: delay_seconds, max_delay_seconds: max_delay_seconds,
    retry_on_timeout: retry_on_timeout,
    retry_on_connection_error: retry_on_connection_error,
    retry_statuses: retry_statuses, retry_statuses_except: retry_statuses_except
  )
end