Class: TasksScheduler::Checker

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/tasks_scheduler/checker.rb,
lib/tasks_scheduler/checker/log.rb

Defined Under Namespace

Classes: Log

Constant Summary collapse

CHECK_INTERVAL =
15
LOG_ON_FILE_ENV_KEY =
'TASKS_SCHEDULER_LOG_ON_FILE'
LOGS_KEYS =
%w[rails stdout stderr].freeze

Instance Method Summary collapse

Instance Method Details

#log_pathObject



25
26
27
# File 'lib/tasks_scheduler/checker.rb', line 25

def log_path
  rais_log.path
end

#logsObject



29
30
31
# File 'lib/tasks_scheduler/checker.rb', line 29

def logs
  LOGS_KEYS.map { |key| send("#{key}_log") }
end

#runObject



13
14
15
16
17
18
19
20
21
22
23
# 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.order(next_run: :asc).each(&:check)
    Rails.logger.info("All tasks checked. Sleeping for #{CHECK_INTERVAL} second(s)...")
    sleep(CHECK_INTERVAL)
  end
end