Class: WorkerArmy::Worker
Instance Attribute Summary collapse
-
#failed ⇒ Object
Returns the value of attribute failed.
-
#job ⇒ Object
Returns the value of attribute job.
-
#processed ⇒ Object
Returns the value of attribute processed.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#worker_name ⇒ Object
Returns the value of attribute worker_name.
Instance Method Summary collapse
-
#initialize(job, worker_name = nil) ⇒ Worker
constructor
A new instance of Worker.
- #process_queue ⇒ Object
Methods inherited from Base
#callback_retry_count, client_retry_count, config, #config, #worker_retry_count
Constructor Details
#initialize(job, worker_name = nil) ⇒ Worker
Returns a new instance of Worker.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/worker_army/worker.rb', line 10 def initialize(job, worker_name = nil) @queue = WorkerArmy::Queue.new @job = job @worker_name = worker_name @host_name = Socket.gethostname @processed = 0 @failed = 0 @config = self.config @log = WorkerArmy::Log.new.log end |
Instance Attribute Details
#failed ⇒ Object
Returns the value of attribute failed.
9 10 11 |
# File 'lib/worker_army/worker.rb', line 9 def failed @failed end |
#job ⇒ Object
Returns the value of attribute job.
9 10 11 |
# File 'lib/worker_army/worker.rb', line 9 def job @job end |
#processed ⇒ Object
Returns the value of attribute processed.
9 10 11 |
# File 'lib/worker_army/worker.rb', line 9 def processed @processed end |
#queue ⇒ Object
Returns the value of attribute queue.
9 10 11 |
# File 'lib/worker_army/worker.rb', line 9 def queue @queue end |
#worker_name ⇒ Object
Returns the value of attribute worker_name.
9 10 11 |
# File 'lib/worker_army/worker.rb', line 9 def worker_name @worker_name end |
Instance Method Details
#process_queue ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/worker_army/worker.rb', line 21 def process_queue raise "No job class set!" unless @job @job.log = @log if @job.respond_to?(:log) @queue.ping(worker_pid: Process.pid, job_name: @job.class.name, host_name: @host_name, timestamp: Time.now.utc.to_i) @log.info("Worker #{@host_name}-#{Process.pid} => Queue: queue_#{@job.class.name}") @log.info("Worker #{@host_name}-#{Process.pid} => Processed: #{@processed} - Failed: #{@failed}") list, element = @queue.pop(@job.class.name) if list and element execute_job(list, element, 0) end end |