PromotionCodeBatch fails generating million codes
DanielePalombo opened this issue · 0 comments
When a new promotion with 2.5m new promo codes was created, it just generated about 250k promo codes and then stopped.
The PromotionBatch screen this error: Errored: #<ActiveRecord::RecordInvalid: Validation failed: Value has already been taken>
It seems that when the PromotionCode creation fails, it raises an exception that stops the worker.
solidus/core/app/models/spree/promotion_code/batch_builder.rb
Lines 36 to 50 in 152b022
I would like to propose changing this behavior and rescuing the exception inside the loop, so we can skip the failed code creation and continue to the next one.
Solidus Version:
All solidus version
To Reproduce
Create a promotion with 2.5M code
Current behavior
The Spree::PromotionCode::BatchBuilder worker fails with ActiveRecord::RecordInvalid: Validation failed: Value has already been taken
without completing the promotion codes generation.
Expected behavior
The Spree::PromotionCode::BatchBuilder worker generates all the PromotionCodes.