class BatchManager::Executor

Public Class Methods

exec(batch_file, options = {}) click to toggle source
# File lib/batch_manager/executor.rb, line 6
def exec(batch_file, options = {})
  @batch_file_path = batch_full_path(batch_file)
  if File.exist?(@batch_file_path)
    @batch_status = BatchManager::BatchStatus.new(@batch_file_path)
    @wet = options[:wet]
    @disable_stdout = options[:daemon]
    if options[:force] || !@wet || @batch_status.can_run?
      log_run_duration { exec_batch_script }
    else
      raise "Cannot run this batch."
    end
  else
    raise "File not exist."
  end
end

Protected Class Methods

exec_batch_script() click to toggle source
# File lib/batch_manager/executor.rb, line 33
def exec_batch_script
  write_log_header
  eval(File.read(@batch_file_path), nil, @batch_file_path)
  @logger.info "Succeeded."
  @batch_status.update_schema if @wet
rescue => e
  @logger.error e
ensure
  puts "Log saved at: #{@logger.log_file}" if @logger.log_file
end
log_run_duration() { || ... } click to toggle source
# File lib/batch_manager/executor.rb, line 24
def log_run_duration
  @logger = BatchManager::Logger.new(@batch_status.name, @wet, @disable_stdout)
  start_at = Time.now
  yield
  end_at = Time.now
  @logger.info "End at: #{end_at.strftime("%Y-%m-%d %H:%M:%S")} (#{(end_at - start_at).to_i}s)"
  @logger.close
end
write_log_header() click to toggle source
# File lib/batch_manager/executor.rb, line 44
def write_log_header
  @logger.info "=============================="
  @logger.info "= #{@wet ? 'WET' : 'DRY'} RUN"
  @logger.info "= Ran at: #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}"
  @logger.info "=============================="
end