Class: OstRunner::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/ost_runner/worker.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  @queue_name = queue_name
  @daemon = options[:daemon]
  @size = options[:pool] || 1
end

Instance Attribute Details

#queue_nameObject (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

#sizeObject (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

#startObject



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