Class: Appsignal::Hooks::UnicornHook

Inherits:
Hook
  • Object
show all
Defined in:
lib/appsignal/hooks/unicorn.rb

Instance Method Summary collapse

Methods inherited from Hook

#installed?, register, #try_to_install

Instance Method Details

#dependencies_present?Boolean

Returns:

  • (Boolean)


6
7
8
9
# File 'lib/appsignal/hooks/unicorn.rb', line 6

def dependencies_present?
  defined?(::Unicorn::HttpServer) &&
    defined?(::Unicorn::Worker)
end

#installObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/appsignal/hooks/unicorn.rb', line 11

def install
  # Make sure that appsignal is started and the last transaction
  # in a worker gets flushed.
  #
  # We'd love to be able to hook this into Unicorn in a less
  # intrusive way, but this is the best we can do given the
  # options we have.

  ::Unicorn::HttpServer.class_eval do
    alias worker_loop_without_appsignal worker_loop

    def worker_loop(worker)
      Appsignal.forked
      worker_loop_without_appsignal(worker)
    end
  end

  ::Unicorn::Worker.class_eval do
    alias close_without_appsignal close

    def close
      Appsignal.stop('unicorn')
      close_without_appsignal
    end
  end
end