diff --git a/app/jobs/pay_pal_prepay_processing_job.rb b/app/jobs/pay_pal_prepay_processing_job.rb index cf88cd75..5b025b37 100644 --- a/app/jobs/pay_pal_prepay_processing_job.rb +++ b/app/jobs/pay_pal_prepay_processing_job.rb @@ -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 diff --git a/app/jobs/premium_downgrade_job.rb b/app/jobs/premium_downgrade_job.rb new file mode 100644 index 00000000..c4ad07e2 --- /dev/null +++ b/app/jobs/premium_downgrade_job.rb @@ -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 \ No newline at end of file