diff options
Diffstat (limited to 'lib/solidus_subscriptions/processor.rb')
-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 |