lib/rocket_job/cli.rb in rocketjob-3.4.3 vs lib/rocket_job/cli.rb in rocketjob-3.5.0
- old
+ new
@@ -2,11 +2,11 @@
require 'semantic_logger'
require 'mongoid'
require 'rocketjob'
require 'rocket_job/extensions/mongoid/factory'
module RocketJob
- # Command Line Interface parser for RocketJob
+ # Command Line Interface parser for Rocket Job
class CLI
include SemanticLogger::Loggable
attr_accessor :name, :workers, :environment, :pidfile, :directory, :quiet,
:log_level, :log_file, :mongo_config, :symmetric_encryption_config,
:filter
@@ -39,11 +39,11 @@
RocketJob::Config.load!(environment, mongo_config, symmetric_encryption_config) if ::Mongoid::Config.clients.empty?
opts = {}
opts[:name] = name if name
opts[:max_workers] = workers if workers
- opts[:filter] = {:_type => filter} if filter
+ opts[:filter] = {_type: filter} if filter
Server.run(opts)
end
def rails?
@rails ||= begin
@@ -68,32 +68,34 @@
end
# 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
- logger.measure_info('Eager loaded Rails and all Engines') do
- Rails.application.eager_load!
- Rails::Engine.subclasses.each(&:eager_load!)
- self.class.eager_load_jobs(File.expand_path('jobs', File.dirname(__FILE__)))
- end
+ return unless Rails.configuration.eager_load
+
+ logger.measure_info('Eager loaded Rails and all Engines') do
+ Rails.application.eager_load!
+ Rails::Engine.subclasses.each(&:eager_load!)
+ self.class.eager_load_jobs(File.expand_path('jobs', File.dirname(__FILE__)))
end
end
# In a standalone environment, explicitly load config files
def boot_standalone
# Try to load bundler if present
begin
require 'bundler/setup'
Bundler.require(environment)
rescue LoadError
+ nil
end
require 'rocketjob'
begin
require 'rocketjob_pro'
rescue LoadError
+ nil
end
# Log to file except when booting rails, when it will add the log file path
path = log_file ? Pathname.new(log_file) : Pathname.pwd.join("log/#{environment}.log")
path.dirname.mkpath
@@ -136,14 +138,14 @@
::Mongoid.logger = SemanticLogger[::Mongoid]
::Mongo::Logger.logger = SemanticLogger[::Mongo]
end
# Eager load files in jobs folder
- def self.eager_load_jobs(path = 'jobs')
- Pathname.glob("#{path}/**/*.rb").each do |path|
+ def self.eager_load_jobs(job_path = 'jobs')
+ Pathname.glob("#{job_path}/**/*.rb").each do |path|
next if path.directory?
- logger.debug "Loading #{path.to_s}"
+ logger.debug "Loading #{path}"
require path.expand_path.to_s
end
end
# Parse command line options placing results in the corresponding instance variables
@@ -196,8 +198,7 @@
puts parser
exit 1
end
parser.parse! argv
end
-
end
end