Class: Rundeck::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/rundeck-ruby-client/job.rb

Defined Under Namespace

Classes: JobExecutionQueryBuilder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, project, id, name) ⇒ Job

Returns a new instance of Job.



17
18
19
20
21
22
# File 'lib/rundeck-ruby-client/job.rb', line 17

def initialize(session, project, id, name)
  @session = session
  @project = project
  @id = id
  @name = name
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



24
25
26
# File 'lib/rundeck-ruby-client/job.rb', line 24

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/rundeck-ruby-client/job.rb', line 24

def name
  @name
end

#projectObject (readonly)

Returns the value of attribute project.



24
25
26
# File 'lib/rundeck-ruby-client/job.rb', line 24

def project
  @project
end

#sessionObject (readonly)

Returns the value of attribute session.



24
25
26
# File 'lib/rundeck-ruby-client/job.rb', line 24

def session
  @session
end

Class Method Details

.find(session, id) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/rundeck-ruby-client/job.rb', line 4

def self.find(session, id)
  result = session.get("api/1/job/#{id}", 'joblist', 'job')
  return nil unless result
  project = Project.find(session, result['context']['project'])
  return nil unless project
  Job.new(session, project, result['id'], result['name'])
end

.from_hash(session, hash) ⇒ Object



12
13
14
15
# File 'lib/rundeck-ruby-client/job.rb', line 12

def self.from_hash(session, hash)
  project = Project.find(session, hash['project'])
  new(session, project, hash['id'], hash['name'])
end

Instance Method Details

#execute!(args_hash) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/rundeck-ruby-client/job.rb', line 36

def execute!(args_hash)
  argstr=""
  args_hash.map {|param, value| argstr += "-#{param} \"#{value}\" "}
  encoded_args = URI::encode(argstr)
  query = "api/1/job/#{id}/run?argString=#{encoded_args}"
  hash = session.get(query, 'result', 'executions', 'execution') || {}
  Execution.new(session, hash, self)
end

#executions {|qb| ... } ⇒ Object

Yields:

  • (qb)


26
27
28
29
30
31
32
33
34
# File 'lib/rundeck-ruby-client/job.rb', line 26

def executions
  qb = JobExecutionQueryBuilder.new
  yield qb if block_given?

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