Class: Mettric::Worker

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

Instance Method Summary collapse

Constructor Details

#initialize(queue, config = Mettric.config) ⇒ Worker

Returns a new instance of Worker.



2
3
4
5
6
7
# File 'lib/mettric/worker.rb', line 2

def initialize(queue, config = Mettric.config)
  @queue = queue
  @config = config
  @stop = false
  @started = false
end

Instance Method Details

#loopObject



16
17
18
19
20
21
22
23
# File 'lib/mettric/worker.rb', line 16

def loop
  Mettric::Client.new(@config) do |client|
    deliver(client,  service: 'mettric.worker.start', metric: 1) rescue nil
    while payload = @queue.pop
      deliver(client, payload)
    end
  end
end

#startObject



9
10
11
12
13
14
# File 'lib/mettric/worker.rb', line 9

def start
  return false if @started
  puts "Mettric::Worker#start" if @config[:debug]
  @started = true
  loop
end

#stopObject



25
26
27
28
# File 'lib/mettric/worker.rb', line 25

def stop
  puts "Mettric::Worker#stop" if @config[:debug]
  @started = false
end