Class: TimeOffWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/workers/time_off_worker.rb

Instance Method Summary collapse

Instance Method Details

#performObject



6
7
8
9
10
# File 'app/workers/time_off_worker.rb', line 6

def perform
  process_pending_requests
  process_pending_work_schedules
  process_employees
end

#process_employeesObject



29
30
31
32
33
34
35
36
37
# File 'app/workers/time_off_worker.rb', line 29

def process_employees
  Employee.active_employees.find_each do |employee|
    employee.process_accruals
    employee.process_time_off_requests
    employee.process_work_schedule_transitions
    employee.process_rollover_and_expiry
    employee.process_policy_transitions
  end
end

#process_pending_requestsObject



17
18
19
20
21
22
23
24
25
26
27
# File 'app/workers/time_off_worker.rb', line 17

def process_pending_requests
  # Reminder sent to managers for pending requests
  pending_reminder_requests = TimeOffRequest.where(state: 'requested').where(created_at: 3.days.ago..1.day.ago)
  pending_reminder_requests.each do |request|
    InternalMailer.new_time_off_request(request).deliver_now
  end

  # Final reminder sent to all managers for pending requests
  pending_requests = TimeOffRequest.where(state: 'requested').where('created_at > ?', 3.days.ago)
  InternalMailer.pending_time_off_requests(pending_requests).deliver_now if pending_requests.any?
end

#process_pending_work_schedulesObject



12
13
14
15
# File 'app/workers/time_off_worker.rb', line 12

def process_pending_work_schedules
  pending_schedules = WorkSchedule.where(state: 'pending')
  InternalMailer.pending_work_schedules(pending_schedules).deliver_now if pending_schedules.any?
end