Class: Rundeck::Execution
- Inherits:
-
Object
- Object
- Rundeck::Execution
- Defined in:
- lib/rundeck-ruby/execution.rb
Defined Under Namespace
Classes: SearchQueryBuilder
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#date_ended ⇒ Object
readonly
Returns the value of attribute date_ended.
-
#date_started ⇒ Object
readonly
Returns the value of attribute date_started.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#job ⇒ Object
readonly
Returns the value of attribute job.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(session, hash, job) ⇒ Execution
constructor
A new instance of Execution.
- #output ⇒ Object
- #wait_for_complete(poll_interval, timeout) ⇒ Object
Constructor Details
#initialize(session, hash, job) ⇒ Execution
Returns a new instance of Execution.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rundeck-ruby/execution.rb', line 26 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 |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
40 41 42 |
# File 'lib/rundeck-ruby/execution.rb', line 40 def args @args end |
#date_ended ⇒ Object (readonly)
Returns the value of attribute date_ended.
40 41 42 |
# File 'lib/rundeck-ruby/execution.rb', line 40 def date_ended @date_ended end |
#date_started ⇒ Object (readonly)
Returns the value of attribute date_started.
40 41 42 |
# File 'lib/rundeck-ruby/execution.rb', line 40 def date_started @date_started end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
40 41 42 |
# File 'lib/rundeck-ruby/execution.rb', line 40 def id @id end |
#job ⇒ Object (readonly)
Returns the value of attribute job.
40 41 42 |
# File 'lib/rundeck-ruby/execution.rb', line 40 def job @job end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
40 41 42 |
# File 'lib/rundeck-ruby/execution.rb', line 40 def session @session end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
40 41 42 |
# File 'lib/rundeck-ruby/execution.rb', line 40 def status @status end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
40 41 42 |
# File 'lib/rundeck-ruby/execution.rb', line 40 def url @url end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
40 41 42 |
# File 'lib/rundeck-ruby/execution.rb', line 40 def user @user end |
Class Method Details
.find(session, id) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/rundeck-ruby/execution.rb', line 42 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) ⇒ Object
21 22 23 24 |
# File 'lib/rundeck-ruby/execution.rb', line 21 def self.from_hash(session, hash) job = Job.from_hash(session, hash['job']) new(session, hash, job) end |
.where(project) {|qb| ... } ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rundeck-ruby/execution.rb', line 50 def self.where(project) qb = SearchQueryBuilder.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 |
Instance Method Details
#output ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rundeck-ruby/execution.rb', line 61 def output path = "api/9/execution/#{id}/output" ret = session.get(path) result = ret['result'] raise APIFailure.new(path, result) unless result && result['success']=='true' #sort the output by node ret = result['output'].slice(*%w(id completed hasFailedNodes)) ret['log'] = result['output']['entries']['entry'].group_by{|e| e['node']} ret end |
#wait_for_complete(poll_interval, timeout) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rundeck-ruby/execution.rb', line 73 def wait_for_complete(poll_interval, timeout) Timeout.timeout(timeout) do while (cur = self.class.find(session, id)).status != :succeeded raise ExecutionFailure.new(self) if cur.status == :failed sleep(poll_interval) end end rescue Timeout::Error raise ExecutionTimeout.new(self) end |