Class: WerckerAPI::PipelineRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/wercker_api/pipeline_runner.rb

Defined Under Namespace

Classes: Timeout

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, max_attempts: 20, delay: 10) ⇒ PipelineRunner

Returns a new instance of PipelineRunner.



27
28
29
30
31
32
# File 'lib/wercker_api/pipeline_runner.rb', line 27

def initialize(client, max_attempts: 20, delay: 10)
  self.client          = client
  self.max_attempts     = max_attempts
  self.delay           = delay
  self.current_attempt = 0
end

Instance Attribute Details

#delayObject

Returns the value of attribute delay.



25
26
27
# File 'lib/wercker_api/pipeline_runner.rb', line 25

def delay
  @delay
end

#max_attemptsObject

Returns the value of attribute max_attempts.



25
26
27
# File 'lib/wercker_api/pipeline_runner.rb', line 25

def max_attempts
  @max_attempts
end

Instance Method Details

#run(pipeline_id, trigger_run_params = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/wercker_api/pipeline_runner.rb', line 34

def run(pipeline_id, trigger_run_params = {})
  run = client.trigger_run pipeline_id, trigger_run_params

  while %w[running notstarted].include?(run.status)
    raise Timeout.new(pipeline_id, self) if max_attempt_reached?
    sleep @delay
    run = client.run(run.id)
    STDOUT.puts run.status
    puts run.status
    @current_attempt += 1
  end

  run
end