module Geary::Worker
Public Instance Methods
perform_async(*args)
click to toggle source
# File lib/geary/worker.rb, line 8 def perform_async(*args) payload = payload_for(args) operation do |gearman| gearman.submit_job_bg('Geary.default', payload.to_json) end end
Protected Instance Methods
gearman_client()
click to toggle source
# File lib/geary/worker.rb, line 22 def gearman_client @gearman_client || use_gearman_client('gearman://localhost:4730') end
operation(&block)
click to toggle source
# File lib/geary/worker.rb, line 30 def operation(&block) attempts = 0 failure_threshold = 1 begin block.call(gearman_client) rescue attempts += 1 if attempts > failure_threshold raise Error else gearman_client.reconnect retry end end end
payload_for(args)
click to toggle source
# File lib/geary/worker.rb, line 26 def payload_for(args) payload = { class: self.to_s, args: args } end
use_gearman_client(*args)
click to toggle source
# File lib/geary/worker.rb, line 18 def use_gearman_client(*args) @gearman_client = Gearman::Client.new(*args) end