Class: Uc::Unicorn::ReadyWait

Inherits:
Object
  • Object
show all
Includes:
Logger, Helper
Defined in:
lib/uc/unicorn/ready_wait.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#first_worker?, #last_worker?, #old_pid, #restart?

Methods included from Logger

#event_queue, event_stream, #event_stream, logger, #logger, stderr, #stderr

Constructor Details

#initialize(server, worker, run_id: nil, ready_wait: nil) ⇒ ReadyWait

Returns a new instance of ReadyWait.



17
18
19
20
21
22
# File 'lib/uc/unicorn/ready_wait.rb', line 17

def initialize(server, worker, run_id: nil, ready_wait: nil)
  @server = server
  @worker = worker
  @run_id = run_id
  @ready_wait = ready_wait
end

Instance Attribute Details

#ready_waitObject (readonly)

Returns the value of attribute ready_wait.



14
15
16
# File 'lib/uc/unicorn/ready_wait.rb', line 14

def ready_wait
  @ready_wait
end

#run_idObject

Returns the value of attribute run_id.



13
14
15
# File 'lib/uc/unicorn/ready_wait.rb', line 13

def run_id
  @run_id
end

#serverObject (readonly)

Returns the value of attribute server.



14
15
16
# File 'lib/uc/unicorn/ready_wait.rb', line 14

def server
  @server
end

#workerObject (readonly)

Returns the value of attribute worker.



14
15
16
# File 'lib/uc/unicorn/ready_wait.rb', line 14

def worker
  @worker
end

Instance Method Details

#eventObject



48
49
50
# File 'lib/uc/unicorn/ready_wait.rb', line 48

def event
  run_id ? "ready_#{run_id}" : "ready" 
end

#idObject



32
33
34
# File 'lib/uc/unicorn/ready_wait.rb', line 32

def id
  @id ||= worker.nr + 1
end

#mqObject



52
53
54
# File 'lib/uc/unicorn/ready_wait.rb', line 52

def mq
  @mq ||= ::Uc::Mqueue.new(queue_name, max_msg: 10, msg_size: 30)
end

#queue_nameObject



28
29
30
# File 'lib/uc/unicorn/ready_wait.rb', line 28

def queue_name
   @queue_name ||= "#{event_queue}_ready_#{worker.nr}"
end

#runObject



24
25
26
# File 'lib/uc/unicorn/ready_wait.rb', line 24

def run
  wait if ready_wait
end

#waitObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/uc/unicorn/ready_wait.rb', line 36

def wait
  if first_worker?
    event_stream.debug "no wait for worker #{worker.nr}"
    return
  end
  mq.create
  msg = mq.wait(event, ready_wait)
  event_stream.debug "ack worker ready #{worker.nr}"
rescue Errno::ENOENT, Errno::EAGAIN, Errno::EACCES, Errno::ETIMEDOUT => e
  event_stream.warn "ready wait error #{worker.nr}: #{e.class}"
end