Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PromotionCodeBatch fails generating million codes #5379

Closed
DanielePalombo opened this issue Sep 13, 2023 · 0 comments · Fixed by #5830 · May be fixed by #5383
Closed

PromotionCodeBatch fails generating million codes #5379

DanielePalombo opened this issue Sep 13, 2023 · 0 comments · Fixed by #5830 · May be fixed by #5383
Assignees

Comments

@DanielePalombo
Copy link
Contributor

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.

while created_codes < number_of_codes
max_codes_to_generate = [batch_size, number_of_codes - created_codes].min
new_codes = Array.new(max_codes_to_generate) { generate_random_code }.uniq
codes_for_current_batch = get_unique_codes(new_codes)
codes_for_current_batch.each do |value|
Spree::PromotionCode.create!(
value: value,
promotion: promotion,
promotion_code_batch: promotion_code_batch
)
end
created_codes += codes_for_current_batch.size
end

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants