Class: Roundhouse::Fetcher

Inherits:
Object
  • Object
show all
Includes:
Actor, Util
Defined in:
lib/roundhouse/fetch.rb

Overview

The Fetcher blocks on Redis, waiting for a message to process from the queues. It gets the message and hands it to the Manager to assign to a ready Processor.

Constant Summary collapse

TIMEOUT =
1

Constants included from Util

Util::EXPIRY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Actor

included

Methods included from Util

#fire_event, #hostname, #identity, #logger, #process_nonce, #redis, #want_a_hertz_donut?, #watchdog

Methods included from ExceptionHandler

#handle_exception

Constructor Details

#initialize(mgr, options) ⇒ Fetcher

Returns a new instance of Fetcher.



19
20
21
22
23
# File 'lib/roundhouse/fetch.rb', line 19

def initialize(mgr, options)
  @down = nil
  @mgr = mgr
  @strategy = Fetcher.strategy.new(options)
end

Instance Attribute Details

#downObject (readonly)

Returns the value of attribute down.



17
18
19
# File 'lib/roundhouse/fetch.rb', line 17

def down
  @down
end

Instance Method Details

#fetchObject

Fetching is straightforward: the Manager makes a fetch request for each idle processor when Roundhouse starts and then issues a new fetch request every time a Processor finishes a message.

Because we have to shut down cleanly, we can’t block forever and we can’t loop forever. Instead we reschedule a new fetch if the current fetch turned up nothing.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/roundhouse/fetch.rb', line 33

def fetch
  watchdog('Fetcher#fetch died') do
    logger.debug 'Fetcher terminating in #fetch' and return if Roundhouse::Fetcher.done?

    begin
      work = @strategy.retrieve_work
      ::Roundhouse.logger.info("Redis is online, #{Time.now - @down} sec downtime") if @down
      @down = nil

      if work
        @mgr.async.assign(work)
      else
        after(0) { fetch }
      end
    rescue => ex
      handle_fetch_exception(ex)
    end

  end
end