diff --git a/broker/src/main/kotlin/dev/usbharu/owl/broker/service/RetryPolicy.kt b/broker/src/main/kotlin/dev/usbharu/owl/broker/service/RetryPolicy.kt deleted file mode 100644 index fb4c667..0000000 --- a/broker/src/main/kotlin/dev/usbharu/owl/broker/service/RetryPolicy.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.owl.broker.service - -import java.time.Instant -import kotlin.math.pow -import kotlin.math.roundToLong - -interface RetryPolicy { - fun nextRetry(now: Instant, attempt: Int): Instant -} - -class ExponentialRetryPolicy(private val firstRetrySeconds: Int = 30) : RetryPolicy { - override fun nextRetry(now: Instant, attempt: Int): Instant = - now.plusSeconds(firstRetrySeconds.toDouble().pow(attempt + 1.0).roundToLong()) - -} \ No newline at end of file diff --git a/broker/src/main/kotlin/dev/usbharu/owl/broker/service/RetryPolicyFactory.kt b/broker/src/main/kotlin/dev/usbharu/owl/broker/service/RetryPolicyFactory.kt index 86ad27b..3b4d851 100644 --- a/broker/src/main/kotlin/dev/usbharu/owl/broker/service/RetryPolicyFactory.kt +++ b/broker/src/main/kotlin/dev/usbharu/owl/broker/service/RetryPolicyFactory.kt @@ -16,8 +16,11 @@ package dev.usbharu.owl.broker.service +import dev.usbharu.owl.common.retry.ExponentialRetryPolicy +import dev.usbharu.owl.common.retry.RetryPolicy + interface RetryPolicyFactory { - fun factory(name:String):RetryPolicy + fun factory(name: String): RetryPolicy } class DefaultRetryPolicyFactory(private val map: Map) : RetryPolicyFactory { diff --git a/common/src/main/kotlin/dev/usbharu/owl/common/retry/ExponentialRetryPolicy.kt b/common/src/main/kotlin/dev/usbharu/owl/common/retry/ExponentialRetryPolicy.kt new file mode 100644 index 0000000..60180dd --- /dev/null +++ b/common/src/main/kotlin/dev/usbharu/owl/common/retry/ExponentialRetryPolicy.kt @@ -0,0 +1,11 @@ +package dev.usbharu.owl.common.retry + +import java.time.Instant +import kotlin.math.pow +import kotlin.math.roundToLong + +class ExponentialRetryPolicy(private val firstRetrySeconds: Int = 30) : RetryPolicy { + override fun nextRetry(now: Instant, attempt: Int): Instant = + now.plusSeconds(firstRetrySeconds.toDouble().pow(attempt + 1.0).roundToLong()) + +} \ No newline at end of file diff --git a/common/src/main/kotlin/dev/usbharu/owl/common/retry/RetryPolicy.kt b/common/src/main/kotlin/dev/usbharu/owl/common/retry/RetryPolicy.kt index 9042917..04a73a0 100644 --- a/common/src/main/kotlin/dev/usbharu/owl/common/retry/RetryPolicy.kt +++ b/common/src/main/kotlin/dev/usbharu/owl/common/retry/RetryPolicy.kt @@ -16,5 +16,8 @@ package dev.usbharu.owl.common.retry +import java.time.Instant + interface RetryPolicy { + fun nextRetry(now: Instant, attempt: Int): Instant } \ No newline at end of file