lib/rocket_job/cli.rb in rocketjob-2.0.0.rc3 vs lib/rocket_job/cli.rb in rocketjob-2.0.0
- old
+ new
@@ -23,18 +23,28 @@
def run
Thread.current.name = 'rocketjob main'
setup_environment
setup_logger
rails? ? boot_rails : boot_standalone
+# setup_metrics
write_pidfile
opts = {}
opts[:name] = name if name
opts[:max_threads] = threads if threads
Worker.run(opts)
end
+ def setup_metrics
+ SemanticLogger.on_metric do |log|
+ if log.metric.start_with?('rocketjob/')
+ ap log
+ RocketJob::Stats::ShortTerm.increment_metric(log.time, log.name, log.duration, log.metric_amount)
+ end
+ end
+ end
+
def rails?
@rails ||= begin
boot_file = Pathname.new(directory).join('config/environment.rb').expand_path
boot_file.file?
end
@@ -56,11 +66,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.benchmark_info('Eager loaded Rails and all Engines') do
+ RocketJob::Worker.logger.measure_info('Eager loaded Rails and all Engines') do
Rails.application.eager_load!
Rails::Engine.subclasses.each(&:eager_load!)
end
end
end
@@ -81,11 +91,11 @@
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
- SemanticLogger.add_appender(path.to_s, &SemanticLogger::Appender::Base.colorized_formatter)
+ SemanticLogger.add_appender(file_name: path.to_s, formatter: :color)
logger.info "Rails not detected. Running standalone: #{environment}"
RocketJob::Config.load!(environment)
self.class.eager_load_jobs
end
@@ -110,10 +120,10 @@
self.environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
end
end
def setup_logger
- SemanticLogger.add_appender(STDOUT, &SemanticLogger::Appender::Base.colorized_formatter) unless quiet
+ SemanticLogger.add_appender(io: STDOUT, formatter: :color) unless quiet
SemanticLogger.default_level = log_level.to_sym if log_level
# Enable SemanticLogger signal handling for this process
SemanticLogger.add_signal_handler
end