Class: Delayed::WorkQueue::ParentProcess::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/delayed/work_queue/parent_process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(addrinfo) ⇒ Client

Returns a new instance of Client.



57
58
59
# File 'lib/delayed/work_queue/parent_process.rb', line 57

def initialize(addrinfo)
  @addrinfo = addrinfo
end

Instance Attribute Details

#addrinfoObject (readonly)

Returns the value of attribute addrinfo.



55
56
57
# File 'lib/delayed/work_queue/parent_process.rb', line 55

def addrinfo
  @addrinfo
end

Instance Method Details

#get_and_lock_next_available(name, queue_name, min_priority, max_priority) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/delayed/work_queue/parent_process.rb', line 61

def get_and_lock_next_available(name, queue_name, min_priority, max_priority)
  @socket ||= @addrinfo.connect
  Marshal.dump([name, queue_name, min_priority, max_priority], @socket)
  response = Marshal.load(@socket)
  unless response.nil? || (response.is_a?(Delayed::Job) && response.locked_by == name)
    raise(ProtocolError, "response is not a locked job: #{response.inspect}")
  end
  response
rescue SystemCallError, IOError
  # The work queue process died. Return nil to signal the worker
  # process should sleep as if no job was found, and then retry.
  @socket = nil
  nil
end