Class: Syntropy::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/syntropy/server.rb

Constant Summary collapse

PENDING_REQUESTS_GRACE_PERIOD =
0.1
PENDING_REQUESTS_TIMEOUT_PERIOD =
5

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine, env, &app) ⇒ Server

Returns a new instance of Server.



23
24
25
26
27
28
29
# File 'lib/syntropy/server.rb', line 23

def initialize(machine, env, &app)
  @machine = machine
  @env = env
  @app = app || app_from_env
  @server_fds = []
  @accept_fibers = []
end

Class Method Details

.static_app(env) ⇒ Object



21
# File 'lib/syntropy/server.rb', line 21

def self.static_app(env); end

.syntropy_app(_machine, env) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/syntropy/server.rb', line 11

def self.syntropy_app(_machine, env)
  if env[:app_location]
    env[:logger]&.info(message: 'Loading web app', location: env[:app_location])
    require env[:app_location]

    env.merge!(Syntropy.config)
  end
  env[:app]
end

Instance Method Details

#app_from_envObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/syntropy/server.rb', line 31

def app_from_env
  case @env[:app_type]
  when nil, :syntropy
    Server.syntropy_app(@machine, @env)
  when :static
    Server.static_app(@env)
  else
    raise "Invalid app type #{@env[:app_type].inspect}"
  end
end

#runObject



42
43
44
45
46
47
# File 'lib/syntropy/server.rb', line 42

def run
  setup
  @machine.await(@accept_fibers)
rescue UM::Terminate
  graceful_shutdown
end

#stop!Object



49
50
51
# File 'lib/syntropy/server.rb', line 49

def stop!
  graceful_shutdown
end