2019-11-12 12:31:00 +00:00
|
|
|
require "docopt"
|
|
|
|
|
|
|
|
|
|
module Pipeline::Cmd
|
|
|
|
|
|
|
|
|
|
class RouterDaemon
|
|
|
|
|
|
|
|
|
|
SPEC = <<-DOCOPT
|
|
|
|
|
Exercism router.
|
|
|
|
|
|
|
|
|
|
Usage:
|
2019-11-17 17:55:21 +00:00
|
|
|
#{__FILE__} <configuration_file> [--seed=<seed_configuration] [--force-worker-restart]
|
2019-11-12 12:31:00 +00:00
|
|
|
#{__FILE__} -h | --help
|
|
|
|
|
#{__FILE__} --version
|
|
|
|
|
|
|
|
|
|
DOCOPT
|
|
|
|
|
|
|
|
|
|
include Mandate
|
|
|
|
|
|
|
|
|
|
initialize_with :argv
|
|
|
|
|
|
|
|
|
|
def call
|
|
|
|
|
puts "*** Exercism Router ***"
|
|
|
|
|
router.force_worker_restart! if restart_workers?
|
|
|
|
|
router.run
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def options
|
|
|
|
|
@options ||= begin
|
|
|
|
|
Docopt::docopt(SPEC, argv: argv)
|
|
|
|
|
rescue Docopt::Exit => e
|
|
|
|
|
puts e.message
|
|
|
|
|
exit 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def restart_workers?
|
|
|
|
|
options["--force-worker-restart"] == true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def router
|
|
|
|
|
@router ||= begin
|
|
|
|
|
config_file = options["<configuration_file>"]
|
2019-11-17 17:55:21 +00:00
|
|
|
unless File.file?(config_file)
|
|
|
|
|
seed = options["--seed"]
|
|
|
|
|
puts "Seeding config from #{seed}"
|
|
|
|
|
FileUtils.cp(seed, config_file)
|
|
|
|
|
end
|
|
|
|
|
config = Pipeline::Config.new(config_file)
|
|
|
|
|
config.seed_aws!
|
2019-11-15 15:49:05 +00:00
|
|
|
|
2019-11-17 17:55:21 +00:00
|
|
|
context = ZMQ::Context.new
|
2019-11-15 15:49:05 +00:00
|
|
|
|
2019-11-12 14:00:11 +00:00
|
|
|
Pipeline::Rpc::Router.new(context, config)
|
2019-11-12 12:31:00 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|