class Mettric::Worker
Public Class Methods
new(queue, config = Mettric.config)
click to toggle source
# File lib/mettric/worker.rb, line 2 def initialize(queue, config = Mettric.config) @queue = queue @config = config @stop = false @started = false end
Public Instance Methods
loop()
click to toggle source
# 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
start()
click to toggle source
# File lib/mettric/worker.rb, line 9 def start return false if @started puts "Mettric::Worker#start" if @config[:debug] @started = true loop end
stop()
click to toggle source
# File lib/mettric/worker.rb, line 25 def stop puts "Mettric::Worker#stop" if @config[:debug] @started = false end
Private Instance Methods
deliver(client, payload)
click to toggle source
# File lib/mettric/worker.rb, line 32 def deliver(client, payload) puts "Mettric::Worker#deliver #{payload}" if @config[:debug] client << payload end