Module: Motor::Notes::RemindersScheduler
- Defined in:
- lib/motor/notes/reminders_scheduler.rb
Constant Summary collapse
- SCHEDULER_INTERVAL =
1.minute
- CHECK_BEHIND_DURATION =
6.hours
- SCHEDULER_TASK =
Concurrent::TimerTask.new( execution_interval: SCHEDULER_INTERVAL ) { Motor::Notes::RemindersScheduler.call }
- REMINDER_NOTIFICATIONS_JOIN_SQL =
<<~SQL.squish LEFT JOIN motor_notifications ON cast(motor_notifications.record_id as int) = motor_reminders.id AND motor_notifications.record_type = 'Motor::Reminder' SQL
Class Method Summary collapse
Class Method Details
.call ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/motor/notes/reminders_scheduler.rb', line 21 def call ActiveRecord::Base.logger.silence do load_reminders.each do |reminder| ::Motor::NotifyReminderJob.perform_later(reminder) rescue StandardError => e Rails.logger.error(e) end end end |
.load_reminders ⇒ Object
31 32 33 34 35 36 |
# File 'lib/motor/notes/reminders_scheduler.rb', line 31 def load_reminders ::Motor::Reminder .joins(REMINDER_NOTIFICATIONS_JOIN_SQL) .where(scheduled_at: CHECK_BEHIND_DURATION.ago..Time.current.end_of_minute) .where(motor_notifications: { id: nil }) end |