-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loader: Retry failures for all warehouse operations (close #1225)
- Loading branch information
Showing
15 changed files
with
455 additions
and
139 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
62 changes: 62 additions & 0 deletions
62
...der/src/main/scala/com/snowplowanalytics/snowplow/rdbloader/dsl/RetryingTransaction.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2012-2023 Snowplow Analytics Ltd. All rights reserved. | ||
* | ||
* This program is licensed to you under the Apache License Version 2.0, | ||
* and you may not use this file except in compliance with the Apache License Version 2.0. | ||
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the Apache License Version 2.0 is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. | ||
*/ | ||
package com.snowplowanalytics.snowplow.rdbloader.dsl | ||
|
||
import cats.{MonadThrow, ~>} | ||
import cats.implicits._ | ||
import retry._ | ||
|
||
import com.snowplowanalytics.snowplow.rdbloader.config.Config | ||
import com.snowplowanalytics.snowplow.rdbloader.loading.Retry | ||
import com.snowplowanalytics.snowplow.rdbloader.loading.Retry._ | ||
import com.snowplowanalytics.snowplow.rdbloader.transactors.RetryingTransactor | ||
|
||
object RetryingTransaction { | ||
|
||
/** A Transaction-handler that retries the io if there is an exception */ | ||
def wrap[F[_]: MonadThrow: Logging: Sleep, C[_]]( | ||
retries: Config.Retries, | ||
inner: Transaction[F, C] | ||
): Transaction[F, C] = { | ||
val policy = Retry.getRetryPolicy[F](retries) | ||
new Transaction[F, C] { | ||
|
||
def transact[A](io: C[A]): F[A] = | ||
withErrorAdaption(policy) { | ||
inner.transact(io) | ||
} | ||
|
||
def run[A](io: C[A]): F[A] = | ||
withErrorAdaption(policy) { | ||
inner.run(io) | ||
} | ||
|
||
def arrowBack: F ~> C = inner.arrowBack | ||
} | ||
} | ||
|
||
private def withErrorAdaption[F[_]: MonadThrow: Sleep: Logging, A](policy: RetryPolicy[F])(io: F[A]): F[A] = | ||
retryingOnSomeErrors(policy, isWorthRetry.andThen(_.pure[F]), onError[F](_, _))(io) | ||
|
||
private val isWorthRetry: Throwable => Boolean = { | ||
case _: RetryingTransactor.ExceededRetriesException => | ||
// The relevant retry policy has already been applied and exceeded | ||
false | ||
case e => | ||
Retry.isWorth(e) | ||
} | ||
|
||
private def onError[F[_]: Logging](t: Throwable, d: RetryDetails): F[Unit] = | ||
Logging[F].error(t)(show"Error executing transaction. $d") | ||
|
||
} |
This file contains 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
This file contains 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
Oops, something went wrong.