Class: DisqueJockey::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/disque_jockey/worker.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ Worker

Returns a new instance of Worker.



4
5
6
# File 'lib/disque_jockey/worker.rb', line 4

def initialize(logger)
  @logger = logger.new(self.class.to_s + rand(1000).to_s)
end

Class Attribute Details

.queue_nameObject (readonly)

Returns the value of attribute queue_name.



14
15
16
# File 'lib/disque_jockey/worker.rb', line 14

def queue_name
  @queue_name
end

.thread_countObject (readonly)

Returns the value of attribute thread_count.



14
15
16
# File 'lib/disque_jockey/worker.rb', line 14

def thread_count
  @thread_count
end

.timeout_secondsObject (readonly)

Returns the value of attribute timeout_seconds.



14
15
16
# File 'lib/disque_jockey/worker.rb', line 14

def timeout_seconds
  @timeout_seconds
end

.use_fast_ackObject (readonly)

Returns the value of attribute use_fast_ack.



14
15
16
# File 'lib/disque_jockey/worker.rb', line 14

def use_fast_ack
  @use_fast_ack
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



3
4
5
# File 'lib/disque_jockey/worker.rb', line 3

def logger
  @logger
end

Class Method Details

.fast_ack(value) ⇒ Object

whehter to use Disque fast acknowledgements



22
23
24
# File 'lib/disque_jockey/worker.rb', line 22

def fast_ack(value)
  @use_fast_ack = !!value
end

.subscribe_to(queue) ⇒ Object

This worker class will subscribe to queue



17
18
19
# File 'lib/disque_jockey/worker.rb', line 17

def subscribe_to(queue)
  @queue_name = queue
end

.threads(size) ⇒ Object

minimum number of worker instances of a given worker class.



27
28
29
# File 'lib/disque_jockey/worker.rb', line 27

def threads(size)
  @thread_count = [[size, 1].max, 10].min
end

.timeout(seconds) ⇒ Object

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



33
34
35
# File 'lib/disque_jockey/worker.rb', line 33

def timeout(seconds)
  @timeout_seconds = [[seconds, 0.01].max, 3600].min
end

Instance Method Details

#log_exception(e) ⇒ Object



8
9
10
11
# 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