Module: Rakwik

Defined in:
lib/rakwik.rb,
lib/rakwik/helpers.rb,
lib/rakwik/tracker.rb,
lib/rakwik/version.rb

Defined Under Namespace

Modules: Helpers Classes: Tracker

Constant Summary collapse

VERSION =
"0.4.3"

Class Method Summary collapse

Class Method Details

.die_gracefully_on_signalObject



34
35
36
37
# File 'lib/rakwik.rb', line 34

def self.die_gracefully_on_signal
  Signal.trap("INT")  { EM.stop }
  Signal.trap("TERM") { EM.stop }
end

.startObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rakwik.rb', line 7

def self.start
  if defined?(PhusionPassenger)
    PhusionPassenger.on_event(:starting_worker_process) do |forked|
    # for passenger, we need to avoid orphaned threads
      if forked && EM.reactor_running?
        EM.stop
      end
      Thread.new {
        EM.run do
          puts "=> EventMachine started"
        end
      }
      die_gracefully_on_signal
    end
  else
    # faciliates debugging
    Thread.abort_on_exception = true
    # just spawn a thread and start it up
    Thread.new {
      EM.run do
        puts "=> EventMachine started"
      end
    } unless defined?(Thin)
    # Thin is built on EventMachine, doesn't need this thread
  end
end