diff options
author | Alessandro Desantis <desa.alessandro@gmail.com> | 2020-11-19 13:14:14 +0100 |
---|---|---|
committer | Alessandro Desantis <desa.alessandro@gmail.com> | 2021-01-30 15:23:41 +0100 |
commit | 0a0659d1150a7df8f0ca23e4876672e95a103f51 (patch) | |
tree | b5d85692c5d9c6d168093a44bbddc10431aa366c /app | |
parent | 5081ffc17562fa90edf0f2a8dfa0d03991480362 (diff) |
Process one installment at a time in background jobs
Instead of attempting to process multiple installments at a time, which
increases the chances something might go wrong, we are now only processing
one installment at a time.
This also improves the extension's performance, because the installments
can be processed in parallel.
Diffstat (limited to 'app')
-rw-r--r-- | app/jobs/solidus_subscriptions/process_installment_job.rb | 11 | ||||
-rw-r--r-- | app/jobs/solidus_subscriptions/process_installments_job.rb | 24 |
2 files changed, 11 insertions, 24 deletions
diff --git a/app/jobs/solidus_subscriptions/process_installment_job.rb b/app/jobs/solidus_subscriptions/process_installment_job.rb new file mode 100644 index 0000000..6beeec6 --- /dev/null +++ b/app/jobs/solidus_subscriptions/process_installment_job.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module SolidusSubscriptions + class ProcessInstallmentJob < ApplicationJob + queue_as SolidusSubscriptions.configuration.processing_queue + + def perform(installment) + Checkout.new([installment]).process + end + end +end diff --git a/app/jobs/solidus_subscriptions/process_installments_job.rb b/app/jobs/solidus_subscriptions/process_installments_job.rb deleted file mode 100644 index e7e1f63..0000000 --- a/app/jobs/solidus_subscriptions/process_installments_job.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -# This job is responsible for creating a consolidated installment from a -# list of installments and processing it. - -module SolidusSubscriptions - class ProcessInstallmentsJob < ApplicationJob - queue_as SolidusSubscriptions.configuration.processing_queue - - # Process a collection of installments - # - # @param installment_ids [Array<Integer>] The ids of the - # installments to be processed together and fulfilled by the same order - # - # @return [Spree::Order] The order which fulfills the list of installments - def perform(installment_ids) - return if installment_ids.empty? - - installments = SolidusSubscriptions::Installment.where(id: installment_ids). - includes(subscription: [:line_items, :user]) - Checkout.new(installments).process - end - end -end |