Class: Uc::Unicorn::Prestart

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

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

Constructor Details

#initialize(server, worker, url: "/") ⇒ Prestart

Returns a new instance of Prestart.



10
11
12
13
14
# File 'lib/uc/unicorn/prestart.rb', line 10

def initialize(server, worker, url: "/")
  @server = server
  @worker = worker
  @url = url
end

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



7
8
9
# File 'lib/uc/unicorn/prestart.rb', line 7

def server
  @server
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/uc/unicorn/prestart.rb', line 7

def url
  @url
end

#workerObject (readonly)

Returns the value of attribute worker.



7
8
9
# File 'lib/uc/unicorn/prestart.rb', line 7

def worker
  @worker
end

Instance Method Details

#appObject



16
17
18
# File 'lib/uc/unicorn/prestart.rb', line 16

def app
  @app ||= server.instance_variable_get("@app")
end

#idObject



37
38
39
# File 'lib/uc/unicorn/prestart.rb', line 37

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

#make_prestart_requestObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/uc/unicorn/prestart.rb', line 24

def make_prestart_request
  event_stream.debug "prestarting worker #{id}"
  response = app.call(rack_request)
  body = response[2]
  if body.is_a? Rack::BodyProxy
    body.close
  end

  event_stream.debug "worker #{id} prestart successful"
rescue => e
  event_stream.warn "prestart failed for worker #{id}, #{e.class}"
end

#runObject



20
21
22
# File 'lib/uc/unicorn/prestart.rb', line 20

def run
  make_prestart_request
end