Sha256: 92f6ed2e68ce0d6ed80a9cd8037a30ba13a72b2a2a2b85970eb888d3ecf89a38

Contents?: true

Size: 895 Bytes

Versions: 1

Compression:

Stored size: 895 Bytes

Contents

require 'concurrent'
require 'concurrent-edge'
require 'consul_bridge/monitor_docker_events'

module ConsulBridge
  class MonitorDockerEventsActor < Concurrent::Actor::RestartingContext
    def initialize(bootstrap_actor:, container_name:)
      @bootstrap_actor = bootstrap_actor
      @container_name = container_name

      tell :monitor
    end

    def on_message(message)
      if message == :monitor
        begin
          MonitorDockerEvents.call!(
            container_name: @container_name,
            handler: ->(event){ @bootstrap_actor << :bootstrap }
          )
        rescue Excon::Errors::SocketError => e
          if Errno::ENOENT === e.cause
            puts "Warning: #{e.cause.message}; retrying in 30 seconds"
            Concurrent::ScheduledTask.execute(30){ tell :monitor }
          end
        end

        nil
      else
        pass
      end
    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_actor.rb