Class: Up::Node::Cluster

Inherits:
Server
  • Object
show all
Defined in:
lib/up/node/cluster.rb

Instance Method Summary collapse

Constructor Details

#initialize(app:, host: 'localhost', port: 3000, scheme: 'http', ca_file: nil, cert_file: nil, key_file: nil, workers: nil) ⇒ Cluster

Returns a new instance of Cluster.



12
13
14
15
16
# File 'lib/up/node/cluster.rb', line 12

def initialize(app:, host: 'localhost', port: 3000, scheme: 'http', ca_file: nil, cert_file: nil, key_file: nil, workers: nil)
  super(app: app, host: host, port: port, scheme: scheme, ca_file: ca_file, cert_file: cert_file, key_file: key_file)
  @workers = workers || `num_workers`
  @members = []
end

Instance Method Details

#listenObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/up/node/cluster.rb', line 18

def listen
  raise "already running" unless @members.empty?
  %x{
    if (cluster.isPrimary) {
      for (let i = 0; i < #@workers; i++) {
        #@members.push(cluster.fork());
      }
    } else {
      #{super}
    }
  }
end

#stopObject



31
32
33
34
35
36
# File 'lib/up/node/cluster.rb', line 31

def stop
  if Up::CLI::stoppable?
    @members.each { |m| `m.kill()` } 
    @members.clear
  end
end