diff options
author | Alessandro Desantis <desa.alessandro@gmail.com> | 2021-03-09 09:28:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-09 09:28:46 +0100 |
commit | f99c56615bc625e4507e73bbc727ec6fd8b70d59 (patch) | |
tree | 3d2df5d3e48945971a4a37fb6f21b4693b2e2b77 /lib/solidus_subscriptions | |
parent | 1031f7edc12030d92f8c7ce739694793b036b416 (diff) | |
parent | 580fa7b2c62dba52fce7fb87def9eb1254507534 (diff) |
Merge pull request #201 from solidusio-contrib/nirebu/190/move-subscription-processing-to-background-job
Move subscription processing to its own background job
Diffstat (limited to 'lib/solidus_subscriptions')
-rw-r--r-- | lib/solidus_subscriptions/processor.rb | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/lib/solidus_subscriptions/processor.rb b/lib/solidus_subscriptions/processor.rb index ffc274b..04b84e8 100644 --- a/lib/solidus_subscriptions/processor.rb +++ b/lib/solidus_subscriptions/processor.rb @@ -4,32 +4,13 @@ module SolidusSubscriptions class Processor class << self def run - SolidusSubscriptions::Subscription.actionable.find_each(&method(:process_subscription)) - SolidusSubscriptions::Installment.actionable.find_each(&method(:process_installment)) - end - - private - - def process_subscription(subscription) - ActiveRecord::Base.transaction do - subscription.successive_skip_count = 0 - subscription.advance_actionable_date - - subscription.cancel! if subscription.pending_cancellation? - subscription.deactivate! if subscription.can_be_deactivated? - - if SolidusSubscriptions.configuration.clear_past_installments - subscription.installments.unfulfilled.actionable.each do |installment| - installment.update!(actionable_date: nil) - end + SolidusSubscriptions::Subscription + .where(installments: SolidusSubscriptions::Installment.actionable) + .or(SolidusSubscriptions::Subscription.actionable) + .distinct + .find_each do |subscription| + ProcessSubscriptionJob.perform_later(subscription) end - - subscription.installments.create!(actionable_date: Time.zone.now) - end - end - - def process_installment(installment) - ProcessInstallmentJob.perform_later(installment) end end end |