class Toro::Fetcher
Public Class Methods
new(options={})
click to toggle source
# File lib/toro/fetcher.rb, line 5 def initialize(options={}) defaults = { queues: [Toro.options[:default_queue]] } options.reverse_merge!(defaults) @queues = options[:queues] @manager = options[:manager] raise 'No manager provided' if @manager.blank? end
Public Instance Methods
fetch()
click to toggle source
# File lib/toro/fetcher.rb, line 22 def fetch job = retrieve @manager.async.assign(job) if job end
notify()
click to toggle source
# File lib/toro/fetcher.rb, line 15 def notify if @manager.is_ready? job = retrieve @manager.assign(job) if job end end
retrieve()
click to toggle source
# 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