Class: OstRunner::Worker
- Inherits:
-
Object
- Object
- OstRunner::Worker
- Defined in:
- lib/ost_runner/worker.rb
Instance Attribute Summary collapse
-
#queue_name ⇒ Object
readonly
Returns the value of attribute queue_name.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(queue_name, options = {}) ⇒ Worker
constructor
A new instance of Worker.
- #start ⇒ Object
Constructor Details
#initialize(queue_name, options = {}) ⇒ Worker
Returns a new instance of Worker.
5 6 7 8 9 |
# File 'lib/ost_runner/worker.rb', line 5 def initialize(queue_name, = {}) @queue_name = queue_name @daemon = [:daemon] @size = [:pool] || 1 end |
Instance Attribute Details
#queue_name ⇒ Object (readonly)
Returns the value of attribute queue_name.
3 4 5 |
# File 'lib/ost_runner/worker.rb', line 3 def queue_name @queue_name end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
3 4 5 |
# File 'lib/ost_runner/worker.rb', line 3 def size @size end |
Class Method Details
.execute(msg) ⇒ Object
21 22 23 24 |
# File 'lib/ost_runner/worker.rb', line 21 def self.execute(msg) job_data = ActiveSupport::JSON.decode(msg) ActiveJob::Base.execute(job_data) end |
Instance Method Details
#start ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/ost_runner/worker.rb', line 11 def start Array.new(size) do Thread.new do Ost[queue_name].each do |msg| self.class.execute(msg) end end end.each(&:join) end |