2023-02-14 13:10:58 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Notify users about the expiration of their subscription
|
2016-03-23 18:39:41 +01:00
|
|
|
class SubscriptionExpireWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
def perform(expire_in)
|
2023-02-14 13:10:58 +01:00
|
|
|
Subscription.where('expiration_date >= ?', Time.current.at_beginning_of_day).each do |s|
|
|
|
|
if (s.expired_at - expire_in.days).to_date == Time.current.to_date
|
|
|
|
if expire_in.zero?
|
|
|
|
NotificationCenter.call type: 'notify_member_subscription_is_expired',
|
2016-03-23 18:39:41 +01:00
|
|
|
receiver: s.user,
|
|
|
|
attached_object: s
|
2023-02-14 13:10:58 +01:00
|
|
|
NotificationCenter.call type: 'notify_admin_subscription_is_expired',
|
2020-04-29 15:34:30 +02:00
|
|
|
receiver: User.admins_and_managers,
|
2016-03-23 18:39:41 +01:00
|
|
|
attached_object: s
|
|
|
|
else
|
2023-02-14 13:10:58 +01:00
|
|
|
NotificationCenter.call type: 'notify_member_subscription_will_expire_in_7_days',
|
2016-03-23 18:39:41 +01:00
|
|
|
receiver: s.user,
|
|
|
|
attached_object: s
|
2023-02-14 13:10:58 +01:00
|
|
|
NotificationCenter.call type: 'notify_admin_subscription_will_expire_in_7_days',
|
2020-04-29 15:34:30 +02:00
|
|
|
receiver: User.admins_and_managers,
|
2016-03-23 18:39:41 +01:00
|
|
|
attached_object: s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|