Sha256: 13c8d3189198d3a0a1209608b6981c321c0b9cabf11c590a4e98702f4f346479

Contents?: true

Size: 1.09 KB

Versions: 52

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Motor
  module Notes
    module RemindersScheduler
      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

      module_function

      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

      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
    end
  end
end

Version data entries

52 entries across 52 versions & 6 rubygems

Version Path
motor-admin-0.4.36 lib/motor/notes/reminders_scheduler.rb
motor-admin-0.4.35 lib/motor/notes/reminders_scheduler.rb
motor-admin-0.4.34 lib/motor/notes/reminders_scheduler.rb
motor-admin-0.4.33 lib/motor/notes/reminders_scheduler.rb
motor-admin-0.4.32 lib/motor/notes/reminders_scheduler.rb
motor-admin-0.4.31 lib/motor/notes/reminders_scheduler.rb
motor-admin-0.4.30 lib/motor/notes/reminders_scheduler.rb
motor-admin-0.4.29 lib/motor/notes/reminders_scheduler.rb
motor-admin-0.4.28 lib/motor/notes/reminders_scheduler.rb
motor-admin-cstham8-0.4.35 lib/motor/notes/reminders_scheduler.rb
motor-admin-cstham8-0.4.34 lib/motor/notes/reminders_scheduler.rb
motor-admin-cstham8-0.4.33 lib/motor/notes/reminders_scheduler.rb
motor-admin-cstham8-0.4.32 lib/motor/notes/reminders_scheduler.rb
motor-admin-cstham8-0.4.31 lib/motor/notes/reminders_scheduler.rb
motor-admin-cstham8-0.4.30 lib/motor/notes/reminders_scheduler.rb
motor-admin-cstham8-0.4.29 lib/motor/notes/reminders_scheduler.rb
motor-admin-cstham8-0.4.28 lib/motor/notes/reminders_scheduler.rb
motor-admin-cstham8-0.4.27 lib/motor/notes/reminders_scheduler.rb
motor-admin-0.4.27 lib/motor/notes/reminders_scheduler.rb
motor-admin-unosquare-0.4.28 lib/motor/notes/reminders_scheduler.rb