Skip to content

Commit 0d67079

Browse files
Move retry policy in another package and add attempt info in the calllback (#45)
1 parent e967377 commit 0d67079

File tree

13 files changed

+568
-34
lines changed

13 files changed

+568
-34
lines changed

app/build.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-core-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
plugins {
218
alias(libs.plugins.stream.android.application)
319
alias(libs.plugins.kotlin.android)

build.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-core-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
import com.android.build.api.dsl.ApplicationExtension
218
import com.android.build.api.dsl.LibraryExtension
319
import com.vanniktech.maven.publish.MavenPublishBaseExtension
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-core-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/

settings.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-core-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
include(":stream-android-core-annotations")
218

319

stream-android-core-annotations/build.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-core-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
plugins {
218
alias(libs.plugins.jetbrains.kotlin.jvm)
319
alias(libs.plugins.stream.java.library)

stream-android-core-lint/build.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-core-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
plugins {
218
alias(libs.plugins.jetbrains.kotlin.jvm)
319
alias(libs.plugins.stream.java.library)

stream-android-core/build.gradle.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-core-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
@file:OptIn(ExperimentalAbiValidation::class)
218

319
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-core-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.getstream.android.core.api.model.retry
18+
19+
import io.getstream.android.core.annotations.StreamInternalApi
20+
21+
/**
22+
* Snapshot describing the state of the current retry loop iteration.
23+
*
24+
* Instances are delivered to the `block` passed into
25+
* [StreamRetryProcessor.retry][io.getstream.android.core.api.processing.StreamRetryProcessor.retry]
26+
* before each attempt so callers can log, alter metrics, or branch based on the retry count.
27+
*
28+
* @property attempt 1-based attempt index. `1` represents the first invocation after the initial
29+
* failure.
30+
* @property currentDelay Delay (in milliseconds) that was applied before this attempt. Equals the
31+
* policy's `initialDelayMillis` for the first retry.
32+
* @property previousAttemptError The error thrown by the previous attempt, if any. `null` for the
33+
* first attempt.
34+
* @property policy The retry policy governing this run; useful if callers need to inspect limits
35+
* (max retries, back-off window, etc.).
36+
*/
37+
@StreamInternalApi
38+
public data class StreamRetryAttemptInfo(
39+
val attempt: Int,
40+
val currentDelay: Long,
41+
val previousAttemptError: Throwable? = null,
42+
val policy: StreamRetryPolicy,
43+
)

stream-android-core/src/main/java/io/getstream/android/core/api/model/StreamRetryPolicy.kt renamed to stream-android-core/src/main/java/io/getstream/android/core/api/model/retry/StreamRetryPolicy.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.getstream.android.core.api.model
17+
package io.getstream.android.core.api.model.retry
1818

1919
import io.getstream.android.core.annotations.StreamInternalApi
2020

stream-android-core/src/main/java/io/getstream/android/core/api/processing/StreamRetryProcessor.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ package io.getstream.android.core.api.processing
1818

1919
import io.getstream.android.core.annotations.StreamInternalApi
2020
import io.getstream.android.core.api.log.StreamLogger
21-
import io.getstream.android.core.api.model.StreamRetryPolicy
21+
import io.getstream.android.core.api.model.retry.StreamRetryAttemptInfo
22+
import io.getstream.android.core.api.model.retry.StreamRetryPolicy
2223
import io.getstream.android.core.internal.processing.StreamRetryProcessorImpl
2324

2425
/**
@@ -54,7 +55,10 @@ public interface StreamRetryProcessor {
5455
* @param block The suspending operation to execute. It should throw on failure; the processor
5556
* handles re-invocation.
5657
*/
57-
public suspend fun <T> retry(policy: StreamRetryPolicy, block: suspend () -> T): Result<T>
58+
public suspend fun <T> retry(
59+
policy: StreamRetryPolicy,
60+
block: suspend (attempt: StreamRetryAttemptInfo) -> T,
61+
): Result<T>
5862
}
5963

6064
/**

0 commit comments

Comments
 (0)