Class: Remind::Service::Scheduler

Inherits:
Object
  • Object
show all
Extended by:
Helper::ErrorHandler, Helper::LogHandler
Defined in:
lib/remind/services/scheduler.rb

Class Method Summary collapse

Methods included from Helper::ErrorHandler

handle_errors

Methods included from Helper::LogHandler

clear_log, create_log

Class Method Details

.startObject

Notify due tasks



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/remind/services/scheduler.rb', line 17

def self.start
  handle_errors do
    tasks = TmsTaskManager::Services::TaskList.list
    puts tasks
    # binding.pry
    messages = []
    tasks.each do |task|
      start_date = Time.parse(task['start_date'])
      due_date = Time.parse(task['end_date'])
      status = task['status']
      task_name = task['title']

      if status == 'completed'
        create_log(Logger::INFO, "Task '#{task_name}' (Completed: #{due_date.strftime('%Y-%m-%d')})")
      elsif Time.now < start_date
        create_log(Logger::INFO, "Task '#{task_name}' (Not Started: #{start_date.strftime('%Y-%m-%d')})")
      elsif Time.now <= due_date
        create_log(Logger::INFO, "Task '#{task_name}' (In Progress: from #{start_date.strftime('%Y-%m-%d')} to #{due_date.strftime('%Y-%m-%d')})")
      else
        create_log(Logger::ERROR, "Task '#{task_name}' (Overdue: from #{start_date.strftime('%Y-%m-%d')} to #{due_date.strftime('%Y-%m-%d')})")
        messages << "Task '#{task_name}' (Overdue: from #{start_date.strftime('%Y-%m-%d')} to #{due_date.strftime('%Y-%m-%d')})"
      end
    end

    Remind::Service::Notifier.notify(messages.join("\n"))
  end
end