Sha256: a921406114d388d1526c188df214260cf25094d57f278a63a50fbbaf26db3c1b

Contents?: true

Size: 1.16 KB

Versions: 7

Compression:

Stored size: 1.16 KB

Contents

# JobQueue abstracts the task of adding work to a queue.
# 
# Beanstalk is fantastic, but maybe not "enterprise grade".
# 
# AMQP is fantastic, but it's bloody complex and has to run inside an
# eventmachine loop.
# 
# Take your pick!
# 
# Before use, an adapter must be chosen:
# 
#   JobQueue.adapter = JobQueue::BeanstalkAdapter.new
# 
# Jobs can then be simply added to the queue with
# 
#   JobQueue.put("flubble bubble")
# 
class JobQueue
  class << self
    attr_accessor :adapter
    attr_accessor :logger
    
    def logger
      @logger ||= begin
        logger = Logger.new(STDOUT)
        logger.level = Logger::WARN
        logger.debug("Created logger")
        logger
      end
    end
  end
  
  def self.put(string)
    adapter.put(string)
  end
  
  def self.subscribe(error_report = nil, &block)
    catch :stop do
      error_report ||= Proc.new do |job, e|
        JobQueue.logger.error \
          "Job failed\n" \
          "==========\n" \
          "Job content: #{job.inspect}\n" \
          "Exception: #{e.message}\n" \
          "#{e.backtrace.join("\n")}\n" \
          "\n"
      end
      
      adapter.subscribe(error_report, &block)
    end
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
mloughran-job_queue-0.0.3 lib/job_queue/job_queue.rb
mloughran-job_queue-0.0.4 lib/job_queue/job_queue.rb
newbamboo-job_queue-0.0.5 lib/job_queue/job_queue.rb
newbamboo-job_queue-0.0.6 lib/job_queue/job_queue.rb
newbamboo-job_queue-0.0.7 lib/job_queue/job_queue.rb
newbamboo-job_queue-0.0.8 lib/job_queue/job_queue.rb
strobemonkey-job_queue-0.0.5 lib/job_queue/job_queue.rb