# Schedule event reminder notifications Rails.application.config.after_initialize do # Only schedule in production or when SCHEDULE_REMINDERS is set if Rails.env.production? || ENV["SCHEDULE_REMINDERS"] == "true" # Schedule the reminder scheduler to run daily at 9 AM begin # Use a simple cron-like approach with ActiveJob # This will be handled by solid_queue in production EventReminderSchedulerJob.set(wait_until: next_run_time).perform_later rescue StandardError => e Rails.logger.warn "Could not schedule event reminders: #{e.message}" end end end def next_run_time # Schedule for 9 AM today, or 9 AM tomorrow if it's already past 9 AM target_time = Time.current.beginning_of_day + 9.hours target_time += 1.day if Time.current > target_time target_time end