class TasksScheduler::Checker

Constants

CHECK_INTERVAL
LOGS_KEYS
LOG_ON_FILE_ENV_KEY

Public Instance Methods

log_path() click to toggle source
# File lib/tasks_scheduler/checker.rb, line 25
def log_path
  rais_log.path
end
logs() click to toggle source
# File lib/tasks_scheduler/checker.rb, line 29
def logs
  LOGS_KEYS.map { |key| send("#{key}_log") }
end
run() click to toggle source
# File lib/tasks_scheduler/checker.rb, line 13
def run
  check_log
  running = true
  Signal.trap('TERM') { running = false }
  while running
    Rails.logger.info('Checking all tasks...')
    ::ScheduledTask.all.order(next_run: :asc).each(&:check)
    Rails.logger.info("All tasks checked. Sleeping for #{CHECK_INTERVAL} second(s)...")
    sleep(CHECK_INTERVAL)
  end
end

Private Instance Methods

check_log() click to toggle source
# File lib/tasks_scheduler/checker.rb, line 43
def check_log
  return unless log_on_file?

  ::Rails.logger = ::Logger.new(rails_log.path)
  $stdout.reopen(stdout_log.path, 'w')
  $stderr.reopen(stderr_log.path, 'w')
end
log_on_file?() click to toggle source
# File lib/tasks_scheduler/checker.rb, line 51
def log_on_file?
  ENV[LOG_ON_FILE_ENV_KEY].present?
end