Class: WorkerArmy::Worker
- Inherits:
-
Object
- Object
- WorkerArmy::Worker
- Defined in:
- lib/worker_army/worker.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#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(worker_name = nil) ⇒ Worker
constructor
A new instance of Worker.
- #process_queue ⇒ Object
Constructor Details
#initialize(worker_name = nil) ⇒ Worker
Returns a new instance of Worker.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/worker_army/worker.rb', line 9 def initialize(worker_name = nil) @queue = WorkerArmy::Queue.new @worker_name = worker_name @host_name = Socket.gethostname @processed = 0 @failed = 0 begin # puts "Using config in your home directory" @config = YAML.load(File.read("#{ENV['HOME']}/.worker_army.yml")) rescue Errno::ENOENT # ignore end @log = WorkerArmy::Log.new.log end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/worker_army/worker.rb', line 8 def config @config end |
#failed ⇒ Object
Returns the value of attribute failed.
8 9 10 |
# File 'lib/worker_army/worker.rb', line 8 def failed @failed end |
#job ⇒ Object
Returns the value of attribute job.
8 9 10 |
# File 'lib/worker_army/worker.rb', line 8 def job @job end |
#processed ⇒ Object
Returns the value of attribute processed.
8 9 10 |
# File 'lib/worker_army/worker.rb', line 8 def processed @processed end |
#queue ⇒ Object
Returns the value of attribute queue.
8 9 10 |
# File 'lib/worker_army/worker.rb', line 8 def queue @queue end |
#worker_name ⇒ Object
Returns the value of attribute worker_name.
8 9 10 |
# File 'lib/worker_army/worker.rb', line 8 def worker_name @worker_name end |
Instance Method Details
#process_queue ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/worker_army/worker.rb', line 24 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 ready! Waiting for jobs: #{@job.class.name}") @log.info("Processed: #{@processed} - Failed: #{@failed}") list, element = @queue.pop(@job.class.name) if list and element execute_job(list, element, 0) end end |