2016-03-23 18:39:41 +01:00
|
|
|
class SubscriptionExpireWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
def perform(expire_in)
|
2019-07-10 10:52:29 +02:00
|
|
|
Subscription.where('expiration_date >= ?', Time.now.at_beginning_of_day).each do |s|
|
2016-03-23 18:39:41 +01:00
|
|
|
if (s.expired_at - expire_in.days).to_date == Time.now.to_date
|
|
|
|
if expire_in != 0
|
|
|
|
NotificationCenter.call type: 'notify_member_subscription_will_expire_in_7_days',
|
|
|
|
receiver: s.user,
|
|
|
|
attached_object: s
|
|
|
|
NotificationCenter.call type: 'notify_admin_subscription_will_expire_in_7_days',
|
|
|
|
receiver: User.admins,
|
|
|
|
attached_object: s
|
|
|
|
else
|
|
|
|
NotificationCenter.call type: 'notify_member_subscription_is_expired',
|
|
|
|
receiver: s.user,
|
|
|
|
attached_object: s
|
|
|
|
NotificationCenter.call type: 'notify_admin_subscription_is_expired',
|
|
|
|
receiver: User.admins,
|
|
|
|
attached_object: s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|