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

Feat / access check retry mechanism #483

Conversation

royschut
Copy link
Collaborator

@royschut royschut commented Apr 4, 2024

Access check retry mechanism

This PR adds a retry mechanism to the access check (reloadActiveSubscription()), to make sure that the UI notices granted access, even if the backend takes longer to process a purchase. This also makes it possible to reduce the initial delay. Note: I've left the initial delay after a subscription switch on 3000ms, because a switch presumably always takes long (it was initially set to 7500).

Note

This PR depends on the flaky subscription e2e test fix by @ChristiaanScheermeijer: #494

@royschut royschut changed the title chore(payment): add access check retry mechanism Feat / access check retry mechanism Apr 4, 2024
@royschut royschut marked this pull request as draft April 5, 2024 11:23
@royschut royschut force-pushed the feat/subscription-retry-logic branch 2 times, most recently from e657176 to a59cba9 Compare April 8, 2024 12:30
@royschut royschut changed the base branch from develop to fix/e2e-flaky-subscription-fix April 11, 2024 11:48
@royschut royschut force-pushed the feat/subscription-retry-logic branch from a59cba9 to 8b05c06 Compare April 11, 2024 11:48
@royschut royschut marked this pull request as ready for review April 11, 2024 14:15
@royschut
Copy link
Collaborator Author

royschut commented Apr 16, 2024

Hi @AntonLantukh and @dbudzins, could you have a look at this PR?

@ChristiaanScheermeijer Maybe you can reply on #494, which this one depends on?

@@ -418,6 +418,12 @@ export default class AccountController {

let pendingOffer: Offer | null = null;

if (!activeSubscription && !!retry && retry > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there is at least 1 edge case that this won't behave as intended for; if the viewer already has a subscription and is buying another one to access additional content. Would it be possible to pass an ID or something to the retry / wait recursion so we can keep trying until we see the expected new subscription?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, good suggestion. With the suggested background polling in mind, perhaps we can create a checkSubscription(id) method? We could use it from useCheckAccess(), to make sure that the correct subscription is awaited.

@@ -418,6 +418,12 @@ export default class AccountController {

let pendingOffer: Offer | null = null;

if (!activeSubscription && !!retry && retry > 0) {
const retryDelay = 1500; // Any initial delay has already occured, so we can set this to a fixed value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do some sort of backoff on this? Like retryDelay *= 2, so we cast a wider net?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting suggestion. I'd have to keep some state. Perhaps a good option for an updated version as suggested?

Copy link
Contributor

@dbudzins dbudzins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reloadSubscriptions is used in a lot more places than I would have guessed. Does it make more sense to have a background worker that can just always listen / recheck subscription status? We could have it setup to poll periodically every 5 minutes or something and then when we trigger a change where we expect updates, we can kick it to refresh more frequently until we see an expected new state or a delay backoff reaches the slow polling frequency again? This would also have the benefit that we'd automatically update changes they may occur from external triggers.

@royschut
Copy link
Collaborator Author

reloadSubscriptions is used in a lot more places than I would have guessed. Does it make more sense to have a background worker that can just always listen / recheck subscription status? We could have it setup to poll periodically every 5 minutes or something and then when we trigger a change where we expect updates, we can kick it to refresh more frequently until we see an expected new state or a delay backoff reaches the slow polling frequency again? This would also have the benefit that we'd automatically update changes they may occur from external triggers.

Thanks for your feedback @dbudzins!
I like your suggestion, because it would simplify reloadSubscriptions, and it creates an additional fallback to infinitely reload every so many minutes. I was thinking something like the snippet below, where we keep it simple and only update the AccountController. The reloadSubscriptions method can then be simplified, removing all retry/delay logic. What do you think?

  defaultPollInterval = 5 * 60 * 1000;
  currentPollInterval = this.defaultPollInterval;

  pollSubscriptions = async () => {
    await this.reloadSubscriptions();
    setTimeout(() => {
      if (this.currentPollInterval < this.defaultPollInterval) {
        this.currentPollInterval = Math.min(this.currentPollInterval * 1.5, this.defaultPollInterval);
      }
      this.pollSubscriptions();
    }, this.currentPollInterval);
  };
  acceleratePolling = async (initialDelay: number = 0, acceleratedInterval: number = 1000) => {
    setTimeout(() => {
      this.reloadSubscriptions();

      this.currentPollInterval = acceleratedInterval;
    }, initialDelay);
  };

However, I don't have the time at this moment to refactor and thoroughly test this. It could mess up the UI due to the loading state that keeps toggling unexpectedly. Perhaps we could proceed with this PR, and I could work on a separate PR during the next sprint?

@AntonLantukh AntonLantukh deleted the branch jwplayer:fix/e2e-flaky-subscription-fix April 22, 2024 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants