class Rundeck::Execution

Attributes

args[R]
date_ended[R]
date_started[R]
id[R]
job[R]
session[R]
status[R]
url[R]
user[R]

Public Class Methods

find(session, id) click to toggle source
# File lib/rundeck-ruby-client/execution.rb, line 27
def self.find(session, id)
  result = session.get("api/1/execution/#{id}", *%w(result executions execution))
  return nil unless result
  job = Job.find(session, result['job']['id'])
  return nil unless job
  Execution.new(session, result, job)
end
from_hash(session, hash) click to toggle source
# File lib/rundeck-ruby-client/execution.rb, line 6
def self.from_hash(session, hash)
  job = Job.from_hash(session, hash['job'])
  new(session, hash, job)
end
new(session, hash, job) click to toggle source
# File lib/rundeck-ruby-client/execution.rb, line 11
def initialize(session, hash, job)
  @id = hash['id']
  @url=hash['href']
  @url = URI.join(session.server, URI.split(@url)[5]).to_s if @url # They always return a url of "localhost" for their executions. Replace it with the real URL
  @status=hash['status'].to_sym
  @date_started = hash['date_started']
  @date_ended = hash['date_ended']
  @user = hash['user']
  @args = (hash['argstring'] || "").split
                                  .each_slice(2)
                                  .reduce({}){|acc,cur| acc[cur[0]] = cur[1]; acc}
  @job = job
  @session = session
end
where(project) { |qb| ... } click to toggle source
# File lib/rundeck-ruby-client/execution.rb, line 35
def self.where(project)
  qb = QueryBuilder.new
  yield qb if block_given?

  endpoint = "api/5/executions?project=#{project.name}#{qb.query}"
  pp endpoint
  results = project.session.get(endpoint, 'result', 'executions', 'execution') || []
  results = [results] if results.is_a?(Hash) #Work around an inconsistency in the API
  results.map {|hash| from_hash(project.session, hash)}
end

Public Instance Methods

output() click to toggle source
# File lib/rundeck-ruby-client/execution.rb, line 46
def output
  ret = session.get("api/9/execution/#{id}/output")
  result = ret['result']
  raise "API call not successful" unless result && result['success']=='true'
  ret = result['output'].slice(*%w(id completed hasFailedNodes))
  logs = result['output']['entries']['entry']
  if logs.class == Array
    logs = logs.group_by{|e| e['node']}
  else
    logs = {"localhost" => [logs]}
  end
  ret['log'] = logs
  ret = [ret] if ret.class != Array
  ret
end
wait_end(interval, timeout) click to toggle source

http request are done at each loop so, be nice with interval :)

# File lib/rundeck-ruby-client/execution.rb, line 63
def wait_end interval, timeout
  Timeout.timeout(timeout) do
      exec = Execution::find(@session, @id)
    until exec.status != :running do
      exec = Execution::find(@session, @id)
      sleep interval
    end
  end
  self.output
end