queue a downgrade job several months in the future to reset prepay storage, needs testing

This commit is contained in:
drusepth 2022-03-10 12:51:57 -08:00
parent c4f0ce692f
commit 33495e55ac
2 changed files with 16 additions and 4 deletions

View File

@ -30,10 +30,7 @@ class PayPalPrepayProcessingJob < ApplicationJob
# Add the extra Premium space
SubscriptionService.add_any_referral_bonuses(invoice.user, 'premium')
# Rather than queueing up a job to run N months from now to reset space,
# we'll probably go with a worker that ensures everyone's space is correct
# every day. Worker TBD.
PremiumDowngradeJob.set(wait: (invoice.months).months).perform_later(invoice.user_id)
end
else

View File

@ -0,0 +1,15 @@
class PremiumDowngradeJob < ApplicationJob
queue_as :low_priority
def perform(*args)
user_id = args.shift
user = User.find_by(id: user_id)
raise "No user to downgrade; id=#{user_id}" if user.nil?
# Remove any bonus bandwidth granted by the plan
premium_bandwidth_bonus = BillingPlan.find(4).bonus_bandwidth_kb
user.update!(upload_bandwidth_kb: user.upload_bandwidth_kb - premium_bandwidth_bonus)
end
end