Module: Tipi::Configuration

Defined in:
lib/tipi/config_dsl.rb,
lib/tipi/configuration.rb

Defined Under Namespace

Classes: Assembler, Interpreter

Class Method Summary collapse

Class Method Details

.forked_supervise(config) ⇒ Object



33
34
35
36
37
38
# File 'lib/tipi/configuration.rb', line 33

def forked_supervise(config)
  config[:forked].times do
    spin { Polyphony.watch_process { simple_supervise(config) } }
  end
  suspend
end

.run(config) ⇒ Object



16
17
18
19
# File 'lib/tipi/configuration.rb', line 16

def run(config)
  start_listeners(config)
  config[:forked] ? forked_supervise(config) : simple_supervise(config)
end

.setup_virtual_hosts(config) ⇒ Object



40
41
42
43
44
# File 'lib/tipi/configuration.rb', line 40

def setup_virtual_hosts(config)
  {
    '*': Tipi::DefaultHandler.new(config)
  }
end

.simple_supervise(config) ⇒ Object



26
27
28
29
30
31
# File 'lib/tipi/configuration.rb', line 26

def simple_supervise(config)
  virtual_hosts = setup_virtual_hosts(config)
  start_acceptors(config, virtual_hosts)
  suspend
  # supervise(restart: true)
end

.start_acceptors(config, virtual_hosts) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/tipi/configuration.rb', line 46

def start_acceptors(config, virtual_hosts)
  spin do
    puts "pid: #{Process.pid}"
    while (connection = @server.accept)
      spin { virtual_hosts[:'*'].call(connection) }
    end
  end
end

.start_listeners(config) ⇒ Object



21
22
23
24
# File 'lib/tipi/configuration.rb', line 21

def start_listeners(config)
  puts "Listening on port 1234"
  @server = Polyphony::Net.tcp_listen('0.0.0.0', 1234, { reuse_addr: true, dont_linger: true })
end

.supervise_configObject



8
9
10
11
12
13
14
# File 'lib/tipi/configuration.rb', line 8

def supervise_config
  current_runner = nil
  while (config = receive)
    old_runner, current_runner = current_runner, spin { run(config) }
    old_runner&.stop
  end
end