lib/rocket_job/cli.rb in rocketjob-2.1.3 vs lib/rocket_job/cli.rb in rocketjob-3.0.0.alpha
- old
+ new
@@ -2,36 +2,38 @@
require 'semantic_logger'
module RocketJob
# Command Line Interface parser for RocketJob
class CLI
include SemanticLogger::Loggable
- attr_accessor :name, :threads, :environment, :pidfile, :directory, :quiet, :log_level, :log_file
+ attr_accessor :name, :workers, :environment, :pidfile, :directory, :quiet, :log_level, :log_file, :mongo_config, :symmetric_encryption_config
def initialize(argv)
- @name = nil
- @threads = nil
- @quiet = false
- @environment = nil
- @pidfile = nil
- @directory = '.'
- @log_level = nil
- @log_file = nil
+ @name = nil
+ @workers = nil
+ @quiet = false
+ @environment = nil
+ @pidfile = nil
+ @directory = '.'
+ @log_level = nil
+ @log_file = nil
+ @mongo_config = nil
+ @symmetric_encryption_config = nil
parse(argv)
end
- # Run a RocketJob::Worker from the command line
+ # Run a RocketJob::Server from the command line
def run
Thread.current.name = 'rocketjob main'
setup_environment
setup_logger
rails? ? boot_rails : boot_standalone
write_pidfile
opts = {}
opts[:name] = name if name
- opts[:max_threads] = threads if threads
- Worker.run(opts)
+ opts[:max_workers] = workers if workers
+ Server.run(opts)
end
def rails?
@rails ||= begin
boot_file = Pathname.new(directory).join('config/environment.rb').expand_path
@@ -55,11 +57,11 @@
# Override Rails log level if command line option was supplied
SemanticLogger.default_level = log_level.to_sym if log_level
if Rails.configuration.eager_load
- RocketJob::Worker.logger.measure_info('Eager loaded Rails and all Engines') do
+ logger.measure_info('Eager loaded Rails and all Engines') do
Rails.application.eager_load!
Rails::Engine.subclasses.each(&:eager_load!)
end
end
end
@@ -83,11 +85,11 @@
path = log_file ? Pathname.new(log_file) : Pathname.pwd.join("log/#{environment}.log")
path.dirname.mkpath
SemanticLogger.add_appender(file_name: path.to_s, formatter: :color)
logger.info "Rails not detected. Running standalone: #{environment}"
- RocketJob::Config.load!(environment)
+ RocketJob::Config.load!(environment, mongo_config, symmetric_encryption_config)
self.class.eager_load_jobs
end
# Create a PID file if requested
def write_pidfile
@@ -128,16 +130,20 @@
end
# Parse command line options placing results in the corresponding instance variables
def parse(argv)
parser = OptionParser.new do |o|
- o.on('-n', '--name NAME', 'Unique Name of this worker instance (Default: host_name:PID)') do |arg|
+ o.on('-n', '--name NAME', 'Unique Name of this server (Default: host_name:PID)') do |arg|
@name = arg
end
- o.on('-t', '--threads COUNT', 'Number of worker threads to start') do |arg|
- @threads = arg.to_i
+ o.on('-w', '--workers COUNT', 'Number of workers (threads) to start') do |arg|
+ @workers = arg.to_i
end
+ o.on('-t', '--threads COUNT', 'Deprecated') do |arg|
+ warn '-t and --threads are deprecated, use -w or --workers'
+ @workers = arg.to_i
+ end
o.on('-q', '--quiet', 'Do not write to stdout, only to logfile. Necessary when running as a daemon') do
@quiet = true
end
o.on('-d', '--dir DIR', 'Directory containing Rails app, if not current directory') do |arg|
@directory = arg
@@ -151,9 +157,15 @@
o.on('-f', '--log_file FILE_NAME', 'The log file to write to. Default: log/<environment>.log') do |arg|
@log_file = arg
end
o.on('--pidfile PATH', 'Use PATH as a pidfile') do |arg|
@pidfile = arg
+ end
+ o.on('-m', '--mongo MONGO_CONFIG_FILE_NAME', 'Path and filename of config file. Default: config/mongoid.yml') do |arg|
+ @mongo_config = arg
+ end
+ o.on('-s', '--symmetric-encryption SYMMETRIC_ENCRYPTION_CONFIG_FILE_NAME', 'Path and filename of Symmetric Encryption config file. Default: config/symmetric-encryption.yml') do |arg|
+ @symmetric_encryption_config = arg
end
o.on('-v', '--version', 'Print the version information') do
puts "Rocket Job v#{RocketJob::VERSION}"
exit 1
end