aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/retry
diff options
context:
space:
mode:
authorspacelord <spacelord@yandex-team.ru>2022-02-10 16:48:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:15 +0300
commita0c6d9ad0cf6b94c527a15da147eb24335281b6d (patch)
treeb222e5ac2e2e98872661c51ccceee5da0d291e13 /library/cpp/retry
parent16747e4f77455cca4932df21eb76f12cb0a97a5c (diff)
downloadydb-a0c6d9ad0cf6b94c527a15da147eb24335281b6d.tar.gz
Restoring authorship annotation for <spacelord@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/retry')
-rw-r--r--library/cpp/retry/retry.cpp12
-rw-r--r--library/cpp/retry/retry.h46
2 files changed, 29 insertions, 29 deletions
diff --git a/library/cpp/retry/retry.cpp b/library/cpp/retry/retry.cpp
index efb2ec3dbc..92466cdeca 100644
--- a/library/cpp/retry/retry.cpp
+++ b/library/cpp/retry/retry.cpp
@@ -1,10 +1,10 @@
-#include "retry.h"
-
-#include <util/stream/output.h>
-
+#include "retry.h"
+
+#include <util/stream/output.h>
+
void DoWithRetry(std::function<void()> func, TRetryOptions retryOptions) {
- DoWithRetry(func, retryOptions, true);
-}
+ DoWithRetry(func, retryOptions, true);
+}
bool DoWithRetryOnRetCode(std::function<bool()> func, TRetryOptions retryOptions) {
for (ui32 attempt = 0; attempt <= retryOptions.RetryCount; ++attempt) {
diff --git a/library/cpp/retry/retry.h b/library/cpp/retry/retry.h
index dc70f953b0..c47ff5070f 100644
--- a/library/cpp/retry/retry.h
+++ b/library/cpp/retry/retry.h
@@ -1,15 +1,15 @@
-#pragma once
-
+#pragma once
+
#include "utils.h"
#include <library/cpp/retry/protos/retry_options.pb.h>
-#include <util/datetime/base.h>
-#include <util/generic/maybe.h>
-#include <util/generic/typetraits.h>
-#include <util/generic/yexception.h>
+#include <util/datetime/base.h>
+#include <util/generic/maybe.h>
+#include <util/generic/typetraits.h>
+#include <util/generic/yexception.h>
#include <functional>
-
+
struct TRetryOptions {
ui32 RetryCount;
@@ -18,7 +18,7 @@ struct TRetryOptions {
TDuration SleepRandomDelta;
TDuration SleepIncrement;
TDuration SleepExponentialMultiplier;
-
+
std::function<void(TDuration)> SleepFunction;
TRetryOptions(ui32 retryCount = 3, TDuration sleepDuration = TDuration::Seconds(1), TDuration sleepRandomDelta = TDuration::Zero(),
@@ -32,17 +32,17 @@ struct TRetryOptions {
, SleepFunction(sleepFunction)
{
}
-
+
TRetryOptions& WithCount(ui32 retryCount) {
RetryCount = retryCount;
return *this;
}
-
+
TRetryOptions& WithSleep(TDuration sleepDuration) {
SleepDuration = sleepDuration;
return *this;
}
-
+
TRetryOptions& WithRandomDelta(TDuration sleepRandomDelta) {
SleepRandomDelta = sleepRandomDelta;
return *this;
@@ -71,16 +71,16 @@ struct TRetryOptions {
static TRetryOptions Count(ui32 retryCount) {
return TRetryOptions(retryCount);
}
-
+
static TRetryOptions Default() {
return TRetryOptions();
- }
-
+ }
+
static TRetryOptions NoRetry() {
return TRetryOptions(0);
- }
+ }
};
-
+
template <typename TResult, typename TException = yexception>
TMaybe<TResult> DoWithRetry(std::function<TResult()> func, std::function<void(const TException&)> onFail, TRetryOptions retryOptions, bool throwLast) {
for (ui32 attempt = 0; attempt <= retryOptions.RetryCount; ++attempt) {
@@ -91,16 +91,16 @@ TMaybe<TResult> DoWithRetry(std::function<TResult()> func, std::function<void(co
if (attempt == retryOptions.RetryCount) {
if (throwLast) {
throw;
- }
+ }
} else {
auto sleep = retryOptions.SleepFunction;
sleep(retryOptions.GetTimeToSleep(attempt));
- }
- }
- }
+ }
+ }
+ }
return Nothing();
}
-
+
template <typename TResult, typename TException = yexception>
TMaybe<TResult> DoWithRetry(std::function<TResult()> func, TRetryOptions retryOptions, bool throwLast) {
return DoWithRetry<TResult, TException>(func, [](const TException&){}, retryOptions, throwLast);
@@ -123,9 +123,9 @@ bool DoWithRetry(std::function<void()> func, TRetryOptions retryOptions, bool th
};
return DoWithRetry<void*, TException>(f, [](const TException&){}, retryOptions, throwLast).Defined();
}
-
+
void DoWithRetry(std::function<void()> func, TRetryOptions retryOptions);
-
+
bool DoWithRetryOnRetCode(std::function<bool()> func, TRetryOptions retryOptions);
Y_DECLARE_PODTYPE(TRetryOptions);