Module: TengineJobAgent::CommandUtils::ClassMethods
- Defined in:
- lib/tengine_job_agent/command_utils.rb
Instance Method Summary collapse
Instance Method Details
#load_config ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/tengine_job_agent/command_utils.rb', line 44 def load_config config_path = Dir["{.,./config,/etc}/tengine_job_agent{.yml,.yml.erb}"].first if config_path YAML.load_file(config_path) else DEFAULT_CONFIG end end |
#new_logger(config) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/tengine_job_agent/command_utils.rb', line 73 def new_logger(config) logfile = config['logfile'] unless logfile prefix = self.name.split('::').last.downcase logfile = File.("#{prefix}-#{Process.pid}.log", config['log_dir']) end result = Tengine::Support::NamedLogger.new(File.basename($PROGRAM_NAME), logfile) result.level = Logger::DEBUG result end |
#process(*args) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/tengine_job_agent/command_utils.rb', line 53 def process(*args) config = load_config logger = new_logger(config) Tengine.logger = logger Kernel.at_exit do logger.info("process is exiting now") end begin logger.info("#{self.name}#process starting") new(logger, args, config).process logger.info("#{self.name}#process finished successfully") rescue Exception => e logger.error("#{self.name}#process error: [#{e.class.name}] #{e.}\n " << e.backtrace.join("\n")) return false ensure logger.info("#{self.name}#process finished at the end") end end |