class DisqueJockey::Worker

Attributes

queue_name[R]
thread_count[R]
timeout_seconds[R]
use_fast_ack[R]
logger[R]

Public Class Methods

fast_ack(value) click to toggle source

whehter to use Disque fast acknowledgements

# File lib/disque_jockey/worker.rb, line 22
def fast_ack(value)
  @use_fast_ack = !!value
end
new(logger) click to toggle source
# File lib/disque_jockey/worker.rb, line 4
def initialize(logger)
  @logger = logger.new(self.class.to_s + rand(1000).to_s)
end
subscribe_to(queue) click to toggle source

This worker class will subscribe to queue

# File lib/disque_jockey/worker.rb, line 17
def subscribe_to(queue)
  @queue_name = queue
end
threads(size) click to toggle source

minimum number of worker instances of a given worker class.

# File lib/disque_jockey/worker.rb, line 27
def threads(size)
  @thread_count = [[size, 1].max, 10].min
end
timeout(seconds) click to toggle source

seconds to wait for a job to be handled before timing out the worker. (capped between 0.01 seconds and one hour)

# File lib/disque_jockey/worker.rb, line 33
def timeout(seconds)
  @timeout_seconds = [[seconds, 0.01].max, 3600].min
end

Protected Class Methods

inherited(type) click to toggle source

callback method fired when a class inherits from DisqueJockey::Worker

# File lib/disque_jockey/worker.rb, line 40
def inherited(type)
  # these are the defaults
  type.threads 2
  type.timeout 30
  type.fast_ack false
  # register the new worker type so we can start giving it jobs
  Supervisor.register_worker(type)
end

Public Instance Methods

log_exception(e) click to toggle source
# File lib/disque_jockey/worker.rb, line 8
def log_exception(e)
  logger.error "#{self.class} raised exception #{e.inspect}: "
  logger.error ">   " + e.backtrace.reject{|l| l =~ /\.rvm/ }.join("\n>   ")
end