Module: Rainbows::Base
- Included in:
- Epoll, EventMachine, Revactor, ThreadPool, ThreadSpawn, WriterThreadPool, WriterThreadSpawn, XEpoll, XEpollThreadPool, XEpollThreadSpawn
- Defined in:
- lib/rainbows/base.rb
Overview
base class for Rainbows! concurrency models, this is currently used by ThreadSpawn and ThreadPool models. Base is also its own (non-)concurrency model which is basically Unicorn-with-keepalive, and not intended for production use, as keepalive with a pure prefork concurrency model is extremely expensive.
Class Method Summary collapse
-
.included(klass) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#init_worker_process(worker) ⇒ Object
this method is called by all current concurrency models.
- #process_client(client) ⇒ Object
- #reopen_worker_logs(worker_nr) ⇒ Object
-
#sig_receiver(worker) ⇒ Object
:stopdoc:.
Class Method Details
.included(klass) ⇒ Object
:nodoc:
44 45 46 |
# File 'lib/rainbows/base.rb', line 44 def self.included(klass) # :nodoc: klass.const_set :LISTENERS, Rainbows::HttpServer::LISTENERS end |
Instance Method Details
#init_worker_process(worker) ⇒ Object
this method is called by all current concurrency models
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rainbows/base.rb', line 22 def init_worker_process(worker) # :nodoc: readers = super(worker) Rainbows::Response.setup Rainbows::MaxBody.setup Rainbows.worker = worker # spawn Threads since Logger takes a mutex by default and # we can't safely lock a mutex in a signal handler trap(:USR1) { Thread.new { reopen_worker_logs(worker.nr) } } trap(:QUIT) { Thread.new { Rainbows.quit! } } [:TERM, :INT].each { |sig| trap(sig) { exit!(0) } } # instant shutdown Rainbows::ProcessClient.const_set(:APP, Rainbows.server.app) Thread.new { sig_receiver(worker) } logger.info "Rainbows! #@use worker_connections=#@worker_connections" Rainbows.readers = readers # for Rainbows.quit readers # unicorn 4.8+ needs this end |
#process_client(client) ⇒ Object
40 41 42 |
# File 'lib/rainbows/base.rb', line 40 def process_client(client) client.process_loop end |
#reopen_worker_logs(worker_nr) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/rainbows/base.rb', line 48 def reopen_worker_logs(worker_nr) logger.info "worker=#{worker_nr} reopening logs..." Unicorn::Util.reopen_logs logger.info "worker=#{worker_nr} done reopening logs" rescue Rainbows.quit! # let the master reopen and refork us end |
#sig_receiver(worker) ⇒ Object
:stopdoc:
11 12 13 14 15 16 17 18 19 |
# File 'lib/rainbows/base.rb', line 11 def sig_receiver(worker) begin worker.to_io.kgio_wait_readable worker.kgio_tryaccept # Unicorn::Worker#kgio_tryaccept rescue => e Rainbows.alive or return Unicorn.log_error(Rainbows.server.logger, "signal receiver", e) end while true end |