Class: ConsulBridge::MonitorDockerEvents

Inherits:
Base
  • Object
show all
Defined in:
lib/consul_bridge/monitor_docker_events.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

call

Constructor Details

#initialize(container_name:, handler:) ⇒ MonitorDockerEvents

Returns a new instance of MonitorDockerEvents.



8
9
10
11
# File 'lib/consul_bridge/monitor_docker_events.rb', line 8

def initialize(container_name:, handler:)
  self.container_name = container_name
  self.handler = handler
end

Instance Attribute Details

#container_nameObject

Returns the value of attribute container_name.



6
7
8
# File 'lib/consul_bridge/monitor_docker_events.rb', line 6

def container_name
  @container_name
end

#handlerObject

Returns the value of attribute handler.



6
7
8
# File 'lib/consul_bridge/monitor_docker_events.rb', line 6

def handler
  @handler
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/consul_bridge/monitor_docker_events.rb', line 13

def call
  begin
    filters = {type: [:container], event: [:start], container: [self.container_name]}.to_json
    Docker::Event.stream(filters: filters) do |event|
      self.handler.call(event)
    end
  rescue Docker::Error::TimeoutError
    retry
  rescue Excon::Errors::SocketError => e
    if Errno::ENOENT === e.cause
      raise
    else
      retry
    end
  end
end