Class: TP2::Server
- Inherits:
-
Object
- Object
- TP2::Server
- Defined in:
- lib/tp2/server.rb
Constant Summary collapse
- PENDING_REQUESTS_GRACE_PERIOD =
0.1- PENDING_REQUESTS_TIMEOUT_PERIOD =
5
Class Method Summary collapse
Instance Method Summary collapse
- #app_from_env ⇒ Object
-
#initialize(machine, env, &app) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
Constructor Details
#initialize(machine, env, &app) ⇒ Server
Returns a new instance of Server.
30 31 32 33 34 35 36 |
# File 'lib/tp2/server.rb', line 30 def initialize(machine, env, &app) @machine = machine @env = env @app = app || app_from_env @server_fds = [] @accept_fibers = [] end |
Class Method Details
.rack_app(env) ⇒ Object
12 13 14 15 16 |
# File 'lib/tp2/server.rb', line 12 def self.rack_app(env) raise 'Missing app location' if !env[:app_location] TP2::RackAdapter.load(env[:app_location]) end |
.static_app(env) ⇒ Object
28 |
# File 'lib/tp2/server.rb', line 28 def self.static_app(env); end |
.tp2_app(_machine, env) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/tp2/server.rb', line 18 def self.tp2_app(_machine, env) if env[:app_location] env[:logger]&.info(message: 'Loading web app', location: env[:app_location]) require env[:app_location] env.merge!(TP2.config) end env[:app] end |
Instance Method Details
#app_from_env ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tp2/server.rb', line 38 def app_from_env case @env[:app_type] when nil, :tp2 Server.tp2_app(@machine, @env) when :rack Server.rack_app(@env) when :static Server.static_app(@env) else raise "Invalid app type #{@env[:app_type].inspect}" end end |
#run ⇒ Object
51 52 53 54 55 56 |
# File 'lib/tp2/server.rb', line 51 def run setup @machine.join(*@accept_fibers) rescue UM::Terminate graceful_shutdown end |