Class: DisqueJockey::Worker
- Inherits:
-
Object
- Object
- DisqueJockey::Worker
- Defined in:
- lib/disque_jockey/worker.rb
Class Attribute Summary collapse
-
.queue_name ⇒ Object
readonly
Returns the value of attribute queue_name.
-
.thread_count ⇒ Object
readonly
Returns the value of attribute thread_count.
-
.timeout_seconds ⇒ Object
readonly
Returns the value of attribute timeout_seconds.
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
-
.subscribe_to(queue) ⇒ Object
This worker class will subscribe to queue.
-
.threads(size) ⇒ Object
minimum number of worker instances of a given worker class.
-
.timeout(seconds) ⇒ Object
seconds to wait for a job to be handled before timing out the worker.
Instance Method Summary collapse
-
#initialize(logger) ⇒ Worker
constructor
A new instance of Worker.
- #log_exception(e) ⇒ Object
Constructor Details
#initialize(logger) ⇒ 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_name ⇒ Object (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_count ⇒ Object (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_seconds ⇒ Object (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 |
Instance Attribute Details
#logger ⇒ Object (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
.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.
22 23 24 |
# File 'lib/disque_jockey/worker.rb', line 22 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)
28 29 30 |
# File 'lib/disque_jockey/worker.rb', line 28 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 |