Class: Toro::Fetcher
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(options = {}) ⇒ Fetcher
constructor
A new instance of Fetcher.
- #notify ⇒ Object
- #retrieve ⇒ Object
Methods included from Actor
Constructor Details
#initialize(options = {}) ⇒ Fetcher
Returns a new instance of Fetcher.
5 6 7 8 9 10 11 12 13 |
# File 'lib/toro/fetcher.rb', line 5 def initialize(={}) defaults = { queues: [Toro.[:default_queue]] } .reverse_merge!(defaults) @queues = [:queues] @manager = [:manager] raise 'No manager provided' if @manager.blank? end |
Instance Method Details
#fetch ⇒ Object
22 23 24 25 |
# File 'lib/toro/fetcher.rb', line 22 def fetch job = retrieve @manager.async.assign(job) if job end |
#notify ⇒ Object
15 16 17 18 19 20 |
# File 'lib/toro/fetcher.rb', line 15 def notify if @manager.is_ready? job = retrieve @manager.assign(job) if job end end |
#retrieve ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/toro/fetcher.rb', line 27 def retrieve job = nil queue_list = @queues.map { |queue| "'#{queue}'" }.join(', ') sql = "SELECT * FROM toro_pop(ARRAY[#{queue_list}]::TEXT[], '#{Toro.process_identity}')" result = nil Toro::Database.with_connection do result = Toro::Database.query(sql).first result = nil if result['id'].nil? end return nil if result.nil? Job.instantiate(result) end |