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

Skip ActiveJob retrying for ProcessInstallmentsJob #175

Closed
aldesantis opened this issue Nov 24, 2020 · 4 comments · Fixed by #206
Closed

Skip ActiveJob retrying for ProcessInstallmentsJob #175

aldesantis opened this issue Nov 24, 2020 · 4 comments · Fixed by #206
Assignees
Labels
enhancement Improves an existing feature.
Milestone

Comments

@aldesantis
Copy link
Member

Since ProcessInstallmentsJob is retried daily in any case, we should make sure to disable the default retry logic, to avoid creating tons of canceled orders in case something goes wrong.

@ikraamg ikraamg self-assigned this Jan 22, 2021
@ikraamg
Copy link
Contributor

ikraamg commented Feb 5, 2021

Hi @aldesantis. I may not be understanding correctly, but if we remove the default retry_logic then I think we also don't need the clear_past_installments feature/configuration anymore as we won't have infinite retries.

Is this configuration also preventing the ProcessInstallmentsJob from retrying the failed installment? I suppose there might be a use case still if this is so. Can you please clarify this idea?

@aldesantis
Copy link
Member Author

@ikraamg hey, unfortunately we'll still need clear_past_installments. There are basically two layers of retry logic at play in solidus_subscriptions:

  1. ActiveJob will attempt to retry a background job that fails by delegating that to the underlying adapter (e.g., Sidekiq). This means that if an exception is raised during the execution of a ProcessInstallmentJob, that job will be retried with an exponential backoff.
  2. If the background job doesn't raise an exception, but the installment can't be processed for some other reason (e.g., the user's credit card is declined), solidus_subscriptions also has its own retry mechanism that will retry the installment on the next day. It does this by moving the actionable_date to the next day and re-processing the installment through the Processor service object.

Note that the mechanism described in #2 will also cover any errors described in #1: in other words, if ProcessInstallmentJob raises an exception, the installment will be reprocessed through ActiveJob's native retry mechanism AND, if it still hasn't been processed successfully on the next day, also by solidus_subscriptions. This causes background jobs and cancelled orders to accumulate, and potentially a bad customer experience (e.g., because we might be sending multiple "Failed to process subscription" emails to customers).

This ticket is about disabling ActiveJob's native retry mechanism so that solidus_subscriptions can do its job of retrying failed installments every day until they are processed successfully.

clear_past_installments is still needed because it tells solidus_subscriptions that an installment should only be retried (via its own mechanism) up until the next subscription cycle: if my subscription fails processing today, and the next cycle processes in 7 days, I don't want to be charged for two cycles, just one.

@ikraamg
Copy link
Contributor

ikraamg commented Feb 12, 2021

@aldesantis Thanks for the detailed explanation! I see that I completely misunderstood what was required in this ticket.

In this case, I believe a simple discard_on is needed then 🤔 . Is it safe to discard_on StandardError. I ask because the the documentation indicates the during the perform method, an ActiveJob::DeserializationError will be raised if the record can't be deserialized but it might also raise a CustomAppException for something domain specific.

@aldesantis
Copy link
Member Author

aldesantis commented Feb 12, 2021

@ikraamg I think it’s safe to discard on StandardError, because the installment will be retried on the next day anyway.

We do need to make sure discard_on doesn’t prevent the exception from being raised and notified to services such as Sentry — we don’t want subscription processing to fail silently in production. 😄

@aldesantis aldesantis added the enhancement Improves an existing feature. label Mar 5, 2021
@aldesantis aldesantis added this to the 1.0.0 milestone Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improves an existing feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants