class Gearman::Worker
Public Class Methods
new(address)
click to toggle source
# File lib/gearman/worker.rb, line 13 def initialize(address) @address = URI(address) configure_connection Connection.method(:new_link) end
Public Instance Methods
build_connection()
click to toggle source
# File lib/gearman/worker.rb, line 46 def build_connection @connection = @connect.call(@address) end
can_do(ability)
click to toggle source
# File lib/gearman/worker.rb, line 18 def can_do(ability) @connection.write(Packet::CAN_DO.new(function_name: ability)) end
configure_connection(connection_routine)
click to toggle source
# File lib/gearman/worker.rb, line 55 def configure_connection(connection_routine) @connect = connection_routine reconnect end
disconnect()
click to toggle source
# File lib/gearman/worker.rb, line 40 def disconnect if @connection @connection.terminate if @connection.alive? end end
grab_job()
click to toggle source
# File lib/gearman/worker.rb, line 27 def grab_job @connection.write(Packet::GRAB_JOB.new) @connection.next(Packet::JOB_ASSIGN, Packet::NO_JOB) end
pre_sleep()
click to toggle source
# File lib/gearman/worker.rb, line 22 def pre_sleep @connection.write(Packet::PRE_SLEEP.new) @connection.next(Packet::NOOP) end
reconnect(*_)
click to toggle source
# File lib/gearman/worker.rb, line 50 def reconnect(*_) disconnect build_connection end
work_complete(handle, data)
click to toggle source
# File lib/gearman/worker.rb, line 36 def work_complete(handle, data) @connection.write(Packet::WORK_COMPLETE.new(handle: handle, data: data)) end
work_exception(handle, data)
click to toggle source
# File lib/gearman/worker.rb, line 32 def work_exception(handle, data) @connection.write(Packet::WORK_EXCEPTION.new(handle: handle, data: data)) end