Class: Daemon::MasterProcess::Fork
- Inherits:
-
Object
- Object
- Daemon::MasterProcess::Fork
- Defined in:
- lib/onapp/engine/master_process/middleware/fork.rb
Instance Method Summary (collapse)
- - (Object) call(env)
- - (Object) detach(pid)
-
- (Fork) initialize(app)
constructor
A new instance of Fork.
Constructor Details
- (Fork) initialize(app)
Returns a new instance of Fork
7 8 9 |
# File 'lib/onapp/engine/master_process/middleware/fork.rb', line 7 def initialize(app) @app = app end |
Instance Method Details
- (Object) call(env)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/onapp/engine/master_process/middleware/fork.rb', line 11 def call(env) prepare = proc do $stderr.extend(Daemon::Utils::IOTimestamp) $stdout.reopen(env.log_file, 'a') $stderr.reopen(env.log_file, 'a') $stdout.sync = $stderr.sync = true end run = proc do begin @app.call(env) rescue => ex $stderr.puts "#{ex.class}: #{ex.}" $stderr.puts ex.backtrace.join("\n") end end pid, error = Daemon::Utils::Process.block_and_fork(prepare, 120, &run) detach(pid) [pid, error] end |
- (Object) detach(pid)
33 34 35 36 37 |
# File 'lib/onapp/engine/master_process/middleware/fork.rb', line 33 def detach(pid) Process.detach(pid) rescue => ex $stderr.puts(ex) end |