2025-09-28 07:10:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2025-10-11 08:17:48 -04:00
|
|
|
class Family::Invitations::CleanupJob < ApplicationJob
|
2025-10-13 06:23:01 -04:00
|
|
|
queue_as :families
|
2025-09-28 07:10:07 -04:00
|
|
|
|
|
|
|
|
def perform
|
2025-12-14 06:05:59 -05:00
|
|
|
return unless DawarichSettings.family_feature_enabled?
|
|
|
|
|
|
2025-09-28 07:10:07 -04:00
|
|
|
Rails.logger.info 'Starting family invitations cleanup'
|
|
|
|
|
|
2025-10-07 12:38:06 -04:00
|
|
|
expired_count = Family::Invitation.where(status: :pending)
|
|
|
|
|
.where('expires_at < ?', Time.current)
|
|
|
|
|
.update_all(status: :expired)
|
2025-09-28 07:10:07 -04:00
|
|
|
|
|
|
|
|
Rails.logger.info "Updated #{expired_count} expired family invitations"
|
|
|
|
|
|
|
|
|
|
cleanup_threshold = 30.days.ago
|
2025-11-07 05:49:21 -05:00
|
|
|
deleted_count =
|
|
|
|
|
Family::Invitation.where(status: %i[expired cancelled])
|
|
|
|
|
.where('updated_at < ?', cleanup_threshold)
|
|
|
|
|
.delete_all
|
2025-09-28 07:10:07 -04:00
|
|
|
|
|
|
|
|
Rails.logger.info "Deleted #{deleted_count} old family invitations"
|
|
|
|
|
|
|
|
|
|
Rails.logger.info 'Family invitations cleanup completed'
|
|
|
|
|
end
|
2025-10-04 17:19:00 -04:00
|
|
|
end
|