1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/workers/reservation_reminder_worker.rb
2016-08-23 10:10:58 +02:00

22 lines
816 B
Ruby

class ReservationReminderWorker
include Sidekiq::Worker
## In case the reminder is enabled but no delay were configured, we use this default value
DEFAULT_REMINDER_DELAY = 24.hours
def perform
enabled = Setting.find_by(name: 'reminder_enable').try(:value)
if enabled == 'true'
delay = Setting.find_by(name: 'reminder_delay').try(:value).try(:to_i).try(:hours) || DEFAULT_REMINDER_DELAY
starting = Time.now.beginning_of_hour + delay
ending = starting + 1.hour
Reservation.joins(:slots).where('slots.start_at >= ? AND slots.start_at <= ?', starting, ending).each do |r|
NotificationCenter.call type: 'notify_member_reservation_reminder',
receiver: r.user,
attached_object: r
end
end
end
end