Sha256: 4293a659594fa3a2ca2e7d5fc43f9ce8c6d5a5b97eb8ab363dc90f1437a047e6
Contents?: true
Size: 1020 Bytes
Versions: 6
Compression:
Stored size: 1020 Bytes
Contents
# frozen_string_literal: true class ScheduledTask < ActiveRecord::Base module Log def log_file(identifier) unless log_identifiers.include?(identifier) raise "Log identifier unknown: \"#{identifier}\" (Valid: #{log_identifiers})" end Rails.root.join('log', 'tasks_scheduler', "#{id}_#{identifier}.log") end private def log_identifiers [LOG_RUNNING, LOG_UNSUCCESSFUL, LOG_SUCCESSFUL] end def log_on_start log_file = log_file(LOG_RUNNING) FileUtils.mkdir_p(File.dirname(log_file)) FileUtils.rm_f(log_file) $stdout.reopen(log_file, 'w') $stderr.reopen(log_file, 'w') Rails.logger = ActiveSupport::Logger.new($stdout) end def log_on_end(exception) running_log = log_file(LOG_RUNNING) return unless ::File.exist?(running_log) target_log = exception ? log_file(LOG_UNSUCCESSFUL) : log_file(LOG_SUCCESSFUL) FileUtils.rm_f(target_log) File.rename(running_log, target_log) end end end
Version data entries
6 entries across 6 versions & 1 rubygems