Sha256: 965a89a0cfb24f67447efc5e554000bbc3a7d1001de43a5b1626199f88d293e5

Contents?: true

Size: 764 Bytes

Versions: 1

Compression:

Stored size: 764 Bytes

Contents

require 'metaractor'
require 'docker-api'

module ConsulBridge
  class MonitorDockerEvents
    include Metaractor

    required :container_name, :handler

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

    private
    def container_name
      context.container_name
    end

    def handler
      context.handler
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
consul_bridge-0.1.5 lib/consul_bridge/monitor_docker_events.rb