Class: Threasy::Work::Worker
- Inherits:
-
Object
- Object
- Threasy::Work::Worker
- Defined in:
- lib/threasy/work.rb
Instance Method Summary collapse
-
#initialize(work, id) ⇒ Worker
constructor
A new instance of Worker.
- #log ⇒ Object
- #work ⇒ Object
Constructor Details
#initialize(work, id) ⇒ Worker
Returns a new instance of Worker.
89 90 91 92 |
# File 'lib/threasy/work.rb', line 89 def initialize(work, id) @work = work @id = id end |
Instance Method Details
#work ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/threasy/work.rb', line 94 def work @thread = Thread.start do loop do if args = @work.grab job = args.shift log.debug "Worker ##{@id} has grabbed a job" begin job = eval(job) if job.kind_of?(String) job.respond_to?(:perform) ? job.perform(*args) : job.call(*args) rescue Exception => e log.error %|Worker ##{@id} error: #{e.}\n#{e.backtrace.join("\n")}| end elsif @work.pool.size > @work.min_workers @work.sync { @work.pool.delete self } break end end end end |