Draft
Conversation
Introduce NetworkCancellationRunner to centralize request cancellation and controlled retry scheduling (scheduleTask / scheduleTaskWithCallback, updateRequestID, cancelExistingTasks). Replace inline retry logic in ApiClientImpl and use runners in BKTClientImpl, EvaluationForegroundTask and EventForegroundTask to avoid retrying stale/manual requests. Add a SettableFuture implementation used by the runner, wire a ScheduledExecutorService through Component, and update tests (including new NetworkCancellationRunner and SettableFuture tests) and existing test wiring/expectations accordingly.
…gy, and ignore `test_results.log`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new
NetworkCancellationRunnerutility to centralize and improve the handling of network request retries and cancellations, especially for background tasks. It replaces the previous ad-hoc retry logic within network calls and tasks, ensuring that only the most recent request is executed and that retries are managed consistently. The changes also update the client and task classes to use this new utility, and add supporting infrastructure and tests.Key changes:
Network Retry & Cancellation Infrastructure
NetworkCancellationRunner, a utility that manages retries and cancellation of network requests using a unique request ID, and ensures that only the latest request is active. It supports scheduling tasks with retry logic and optional completion callbacks. (bucketeer/src/main/kotlin/io/bucketeer/sdk/android/internal/remote/NetworkCancellationRunner.kt)SettableFuture, a simple Future implementation to support asynchronous task completion and result propagation in the new runner. (bucketeer/src/main/kotlin/io/bucketeer/sdk/android/internal/util/SettableFuture.kt)Refactoring Client and Task Classes
BKTClientImpl,EvaluationForegroundTask, andEventForegroundTaskto useNetworkCancellationRunnerfor scheduling and retrying network operations, replacing previous direct executor usage and manual retry logic. (bucketeer/src/main/kotlin/io/bucketeer/sdk/android/BKTClientImpl.kt,bucketeer/src/main/kotlin/io/bucketeer/sdk/android/internal/scheduler/EvaluationForegroundTask.kt,bucketeer/src/main/kotlin/io/bucketeer/sdk/android/internal/scheduler/EventForegroundTask.kt) [1] [2] [3]ApiClientImpl, delegating retry and cancellation to the new runner. (bucketeer/src/main/kotlin/io/bucketeer/sdk/android/internal/remote/ApiClientImpl.kt) [1] [2]Dependency Injection and Configuration
ComponentandComponentImplclasses to provideNetworkCancellationRunnerinstances for evaluation and event operations, and to accept an executor as a dependency. (bucketeer/src/main/kotlin/io/bucketeer/sdk/android/internal/di/Component.kt) [1] [2]Testing
NetworkCancellationRunner, including retry, success, and cancellation scenarios. (bucketeer/src/test/kotlin/io/bucketeer/sdk/android/internal/remote/NetworkCancellationRunnerTest.kt)bucketeer/src/test/kotlin/io/bucketeer/sdk/android/internal/evaluation/EvaluationInteractorTest.kt,bucketeer/src/test/kotlin/io/bucketeer/sdk/android/internal/event/EventInteractorTest.kt,bucketeer/src/test/kotlin/io/bucketeer/sdk/android/internal/scheduler/EvaluationForegroundTaskTest.kt) [1] [2] [3] [4]These changes improve the reliability and maintainability of network operations, especially under conditions where requests may be cancelled or retried due to app state changes or connectivity issues.