Class: Smplkit::Jobs::RunsClient

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

Overview

client.jobs.runs.* — read-only run history plus the cancel / rerun run actions.

Instance Method Summary collapse

Constructor Details

#initialize(api, environment: nil) ⇒ RunsClient

Returns a new instance of RunsClient.

Parameters:

  • api (SmplkitGeneratedClient::Jobs::RunsApi)

    The generated runs API.

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

    Default environment scoping #list‘s filter[environment] when no explicit environments are passed.



37
38
39
40
# File 'lib/smplkit/jobs/client.rb', line 37

def initialize(api, environment: nil)
  @api = api
  @environment = environment
end

Instance Method Details

#cancel(run_id) ⇒ Smplkit::Jobs::Run

Cancel a run that has not finished yet.

Parameters:

  • run_id (String)

    Identifier of the run to cancel.

Returns:



96
97
98
99
# File 'lib/smplkit/jobs/client.rb', line 96

def cancel(run_id)
  resp = Jobs.call_api { @api.cancel_run(run_id) }
  Run.from_resource(resp.data, runs: self)
end

#get(run_id) ⇒ Smplkit::Jobs::Run

Fetch a single run by its id.

Parameters:

  • run_id (String)

    Identifier of the run to fetch.

Returns:

Raises:



87
88
89
90
# File 'lib/smplkit/jobs/client.rb', line 87

def get(run_id)
  resp = Jobs.call_api { @api.get_run(run_id) }
  Run.from_resource(resp.data, runs: self)
end

#list(job: nil, environments: nil, triggers: nil, last_run_only: false, page_size: nil, after: nil) ⇒ Array<Smplkit::Jobs::Run>

List past runs, most recent first. Cursor paginated: pass page_size and the after cursor from the prior page. Pass job to scope to a single job’s history.

Parameters:

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

    Return only runs of the job with this id. nil lists runs across all jobs in the account.

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

    Restrict to runs stamped with any of these environment keys. nil falls back to the client’s configured environment (if any), otherwise covers every environment you can access.

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

    Restrict to runs started by any of these triggers (see Smplkit::Jobs::RunTrigger) — e.g. [RunTrigger::RETRY] for automatic retries. Serialized as a comma-joined filter[trigger] (any-of). nil or empty covers every trigger.

  • last_run_only (Boolean) (defaults to: false)

    When true, collapse the result to the last completed (succeeded / failed / canceled) run per job-and-environment; in-flight runs are excluded. The other filters apply first, then the collapse. Defaults to false; the query param is sent only when true.

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

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

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

    Opaque cursor from a previous page; returns the runs that follow it. nil starts from the first page.

Returns:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/smplkit/jobs/client.rb', line 66

def list(job: nil, environments: nil, triggers: nil, last_run_only: false, page_size: nil, after: nil)
  opts = {}
  opts[:filter_job] = job unless job.nil?
  filter_environment = Jobs.resolve_environment_filter(environments, @environment)
  opts[:filter_environment] = filter_environment unless filter_environment.nil?
  opts[:filter_trigger] = triggers.join(",") unless triggers.nil? || triggers.empty?
  # The generated default would emit +last_run_only=false+ on every call;
  # send the param only when explicitly requested.
  opts[:last_run_only] = true if last_run_only
  opts[:page_size] = page_size unless page_size.nil?
  opts[:page_after] = after unless after.nil?

  resp = Jobs.call_api { @api.list_runs(opts) }
  (resp.data || []).map { |r| Run.from_resource(r, runs: self) }
end

#rerun(run_id) ⇒ Smplkit::Jobs::Run

Start a new run that repeats a previous one.

Parameters:

  • run_id (String)

    Identifier of the run to repeat.

Returns:



106
107
108
109
# File 'lib/smplkit/jobs/client.rb', line 106

def rerun(run_id)
  resp = Jobs.call_api { @api.rerun_run(run_id) }
  Run.from_resource(resp.data, runs: self)
end