Class: Sidekiq::Fetcher
- Inherits:
-
Object
- Object
- Sidekiq::Fetcher
- Defined in:
- lib/sidekiq/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
Instance Attribute Summary collapse
-
#down ⇒ Object
readonly
Returns the value of attribute down.
Instance Method Summary collapse
-
#fetch ⇒ Object
Fetching is straightforward: the Manager makes a fetch request for each idle processor when Sidekiq starts and then issues a new fetch request every time a Processor finishes a message.
-
#initialize(mgr, options) ⇒ Fetcher
constructor
A new instance of Fetcher.
Methods included from Actor
Methods included from Util
#fire_event, #hostname, #identity, #logger, #process_nonce, #redis, #want_a_hertz_donut?, #watchdog
Methods included from ExceptionHandler
Constructor Details
Instance Attribute Details
#down ⇒ Object (readonly)
Returns the value of attribute down.
16 17 18 |
# File 'lib/sidekiq/fetch.rb', line 16 def down @down end |
Instance Method Details
#fetch ⇒ Object
Fetching is straightforward: the Manager makes a fetch request for each idle processor when Sidekiq 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.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sidekiq/fetch.rb', line 32 def fetch watchdog('Fetcher#fetch died') do return if Sidekiq::Fetcher.done? begin work = @strategy.retrieve_work ::Sidekiq.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 |