Class: RRRSpec::Server::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/rrrspec/server/cli.rb

Instance Method Summary collapse

Instance Method Details

#serverObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rrrspec/server/cli.rb', line 21

def server
  setup(ServerConfiguration.new)
  RRRSpec.configuration.daemonize = options[:daemonize] unless options[:daemonize] == nil
  RRRSpec.configuration.pidfile = options[:pidfile] unless options[:pidfile] == nil
  RRRSpec.configuration.user = options[:user] unless options[:user] == nil

  RRRSpec::Server.daemonizer('rrrspec-server server') do
    ActiveRecord::Base.establish_connection(**RRRSpec.configuration.persistence_db)
    Thread.abort_on_exception = true
    Thread.fork { Dispatcher.work_loop }
    Thread.fork { Arbiter.work_loop }
    Thread.fork { Persister.work_loop }
    Thread.fork { StatisticsUpdater.work_loop }
    Kernel.sleep
  end
end

#workerObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rrrspec/server/cli.rb', line 43

def worker
  setup(WorkerConfiguration.new)
  RRRSpec.configuration.daemonize = options[:daemonize] unless options[:daemonize] == nil
  RRRSpec.configuration.pidfile = options[:pidfile] unless options[:pidfile] == nil
  RRRSpec.configuration.user = options[:user] unless options[:user] == nil

  RRRSpec::Server.daemonizer('rrrspec-server worker') do
    worker = Worker.create(options[:'worker-type'] || RRRSpec.configuration.worker_type)
    worker_runner = WorkerRunner.new(worker)
    Thread.abort_on_exception = true
    Thread.fork { RRRSpec.pacemaker(worker, 60, 5) }
    Thread.fork { worker_runner.work_loop }
    Kernel.sleep
  end
end