Class: Zapp::Worker::RequestProcessor
- Inherits:
-
Object
- Object
- Zapp::Worker::RequestProcessor
- Defined in:
- lib/zapp/worker/request_processor.rb
Overview
Processes HTTP requests
Instance Attribute Summary collapse
-
#context_pipe ⇒ Object
readonly
Returns the value of attribute context_pipe.
-
#socket_pipe_sender ⇒ Object
readonly
Returns the value of attribute socket_pipe_sender.
Instance Method Summary collapse
-
#initialize(context_pipe:, socket_pipe:) ⇒ RequestProcessor
constructor
A new instance of RequestProcessor.
- #loop ⇒ Object
Constructor Details
#initialize(context_pipe:, socket_pipe:) ⇒ RequestProcessor
Returns a new instance of RequestProcessor.
9 10 11 12 |
# File 'lib/zapp/worker/request_processor.rb', line 9 def initialize(context_pipe:, socket_pipe:) @socket_pipe_sender = Zapp::SocketPipe::Sender.new(pipe: socket_pipe) @context_pipe = context_pipe end |
Instance Attribute Details
#context_pipe ⇒ Object (readonly)
Returns the value of attribute context_pipe.
7 8 9 |
# File 'lib/zapp/worker/request_processor.rb', line 7 def context_pipe @context_pipe end |
#socket_pipe_sender ⇒ Object (readonly)
Returns the value of attribute socket_pipe_sender.
7 8 9 |
# File 'lib/zapp/worker/request_processor.rb', line 7 def socket_pipe_sender @socket_pipe_sender end |
Instance Method Details
#loop ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/zapp/worker/request_processor.rb', line 14 def loop while (context = context_pipe.take) if context.is_a?(Symbol) if context == Zapp::WorkerPool::SIGNALS[:EXIT] Zapp::Logger.trace("Received exit signal, shutting down") shutdown break else next end end process = lambda { process(context: context) } if Zapp.config.log_requests log_request_time(context: context, &process) else process.call end # We send sockets that the client hasn't closed yet, # back to the main ractor for HTTP request parsing again socket_pipe_sender.push(context.socket) unless context.client_closed? end end |