Skip to content

feat: none blocking when retrying#244

Draft
duyhungtnn wants to merge 2 commits intomainfrom
feat/improve-retry-499
Draft

feat: none blocking when retrying#244
duyhungtnn wants to merge 2 commits intomainfrom
feat/improve-retry-499

Conversation

@duyhungtnn
Copy link
Collaborator

@duyhungtnn duyhungtnn commented Feb 8, 2026

This pull request introduces a new NetworkCancellationRunner utility 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

  • Added 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)
  • Introduced 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

  • Updated BKTClientImpl, EvaluationForegroundTask, and EventForegroundTask to use NetworkCancellationRunner for 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]
  • Removed old retry logic from 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

  • Updated the Component and ComponentImpl classes to provide NetworkCancellationRunner instances 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

  • Added comprehensive unit tests for NetworkCancellationRunner, including retry, success, and cancellation scenarios. (bucketeer/src/test/kotlin/io/bucketeer/sdk/android/internal/remote/NetworkCancellationRunnerTest.kt)
  • Updated existing tests and test setups to provide the required executor dependency. (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.

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.
@duyhungtnn duyhungtnn changed the title Add NetworkCancellationRunner and SettableFuture feat: none blocking when retrying Feb 8, 2026
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.

1 participant