Sha256: 8f3c6592e869ccd1562fa52ce5a6ee5d2e5f3b505417d8bf5fc0644bae5e1656

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

module EbDeployer
  class EventPoller
    include Utils

    def initialize(app, env, eb_driver)
      @app, @env, @eb_driver = app, env, eb_driver
    end

    def poll(start_time = Time.now, &block)
      handled = Set.new
      loop do
        fetch_events(start_time) do |events|
          new_events = events.reject { |e| handled.include?(digest(e)) }
          handle(new_events, &block)
          handled += new_events.map { |e| digest(e) }
        end
        sleep 15
      end
    end

    private

    def digest(event)
      JSON.dump(event)
    end

    def handle(events, &block)
      events.reverse.each(&block)
    end

    def fetch_events(start_time, &block)
      events, next_token = fetch_events_from_eb(:start_time => start_time.iso8601)
      yield(events)
      fetch_next(next_token, &block) if next_token
    end

    def fetch_next(next_token, &block)
      events, next_token = fetch_events_from_eb(:next_token => next_token)
      yield(events)
      fetch_next(next_token, &block) if next_token
    end

    def fetch_events_from_eb(options)
      @eb_driver.fetch_events(@app, @env, options)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
eb_deployer-0.4.5 lib/eb_deployer/event_poller.rb
eb_deployer-0.4.4 lib/eb_deployer/event_poller.rb
eb_deployer-0.4.4.beta7 lib/eb_deployer/event_poller.rb
eb_deployer-0.4.4.beta6 lib/eb_deployer/event_poller.rb
eb_deployer-0.4.4.beta5 lib/eb_deployer/event_poller.rb