Class: OpsDeploy::Waiter

Inherits:
Thread
  • Object
show all
Defined in:
lib/ops_deploy/waiter.rb

Overview

A class defining a generic ‘waiter’ thread that waits for tasks to finish

Direct Known Subclasses

InstanceResponseWaiter, DeploymentWaiter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&task) ⇒ Waiter

Returns a new instance of Waiter.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ops_deploy/waiter.rb', line 5

def initialize(&task)
  @task = task

  super() do
    error = nil

    begin
      loop do
        @data = @task.call
        break if @end_when.call(@data)
        sleep 5
      end
    rescue StandardError => e
      error = e
    end

    @callback.call(@data, error) if @callback

    @data
  end
end

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



3
4
5
# File 'lib/ops_deploy/waiter.rb', line 3

def callback
  @callback
end

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/ops_deploy/waiter.rb', line 3

def data
  @data
end

#end_whenObject

Returns the value of attribute end_when.



3
4
5
# File 'lib/ops_deploy/waiter.rb', line 3

def end_when
  @end_when
end