Skip to content

consentGiven true forces wake when delaying for retry#2109

Merged
emawby merged 3 commits intomainfrom
fix/cancel_wait_after_consent_given
Jun 6, 2024
Merged

consentGiven true forces wake when delaying for retry#2109
emawby merged 3 commits intomainfrom
fix/cancel_wait_after_consent_given

Conversation

@emawby
Copy link
Copy Markdown
Contributor

@emawby emawby commented Jun 5, 2024

Description

One Line Summary

Retriable errors now use waiter instead of delay and it can only be interrupted by force calls to waiter.wake or waiting the

Details

We were previously using delay() to wait to retry failed server requests. This included privacy consent not given. This PR adds a way to interrupt that delay when privacy consent goes from false to true.

We cannot use delay() for this so it uses the waiter instead. This has the side effect of making all retry-able errors use the waiter.

Motivation

We want a way to immediately process deltas when privacy consent goes from false to true.

Scope

Retry-able operations and privacy consent given

Testing

Unit testing

OPTIONAL - Explain unit tests added, if not clear in the code.

Manual testing

Tested not giving privacy consent to ensure we were properly delaying retries. Then tested providing privacy consent and ensured that the operations were sent immediately.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

Retriable errors now use waiter instead of delay and it can only be interrupted by force calls to waiter.wake or waiting the full retry duration.
}
}

override fun forceProcessDeltas() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this should be called forceExecuteOperations, since we have the method name executeOperations in this code base.

while (!wakeMessage.force) {
val waitedTheFullTime =
withTimeoutOrNull(delayFor) {
wakeMessage = waiter.waitForWake()
Copy link
Copy Markdown
Member

@jkasten2 jkasten2 Jun 5, 2024

Choose a reason for hiding this comment

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

Thinking about this again it would be better to create a different waiter for this. (calling it something like retryWaiter maybe?). After seeing the code again I have concerns how things will interact on the same waiter, as I don't know think calling wake() will chain to both waits. Sorry for the orignal suggestion of using the same waiter could work.

So here I think we can simply this logic, remove waitedTheFullTime as we want to break out of this wait right away if consent becomes true. Then we can call wake() on orignal waiter, without force or a time so it counts it as a "normal" operation, so we can batch other things like tags together.

@emawby emawby requested a review from jkasten2 June 6, 2024 17:11
withTimeoutOrNull(delayFor) {
retryWaiter.waitForWake()
}
waiter.wake(LoopWaiterMessage(false, 0))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this is a better fit in forceExecuteOperations().

}

override fun forceExecuteOperations() {
retryWaiter.wake(LoopWaiterMessage(true, 0))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit, we can drop the 2nd param of LoopWaiterMessage, it defaults to 0.

@@ -1,5 +1,6 @@
package com.onesignal.core.internal.operations.impl

import android.os.Looper
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It doesn't looks like the new import is used. (it is probably failing ktlint).

Copy link
Copy Markdown
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

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

(see last review comments)

@emawby emawby force-pushed the fix/cancel_wait_after_consent_given branch from 5d901ab to 151ec95 Compare June 6, 2024 17:40
@emawby emawby requested a review from jkasten2 June 6, 2024 17:42
@emawby emawby changed the title WiP consentGiven true forces wake when delaying for retry consentGiven true forces wake when delaying for retry Jun 6, 2024
@emawby emawby force-pushed the fix/cancel_wait_after_consent_given branch from f071a47 to 8d98222 Compare June 6, 2024 21:58
@emawby emawby merged commit 53ddae8 into main Jun 6, 2024
@emawby emawby deleted the fix/cancel_wait_after_consent_given branch June 6, 2024 22:09
@jinliu9508 jinliu9508 mentioned this pull request Jun 7, 2024
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.

2 participants