diff options
author | tolich <tolich@yandex-team.ru> | 2022-02-10 16:48:42 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:42 +0300 |
commit | 9e8a8cd0f33ded91ed66671e388f3af06dd2249e (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/retry/retry.h | |
parent | c662862405cbda305d8b2ff7693adf2595e3edc2 (diff) | |
download | ydb-9e8a8cd0f33ded91ed66671e388f3af06dd2249e.tar.gz |
Restoring authorship annotation for <tolich@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/retry/retry.h')
-rw-r--r-- | library/cpp/retry/retry.h | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/library/cpp/retry/retry.h b/library/cpp/retry/retry.h index d4f1648dec..c47ff5070f 100644 --- a/library/cpp/retry/retry.h +++ b/library/cpp/retry/retry.h @@ -12,23 +12,23 @@ struct TRetryOptions { ui32 RetryCount; - - // TotalDuration = SleepDuration +/- SleepRandomDelta + (attempt * SleepIncrement) + (2**attempt * SleepExponentialMultiplier) + + // TotalDuration = SleepDuration +/- SleepRandomDelta + (attempt * SleepIncrement) + (2**attempt * SleepExponentialMultiplier) TDuration SleepDuration; - TDuration SleepRandomDelta; - TDuration SleepIncrement; - TDuration SleepExponentialMultiplier; + TDuration SleepRandomDelta; + TDuration SleepIncrement; + TDuration SleepExponentialMultiplier; std::function<void(TDuration)> SleepFunction; - TRetryOptions(ui32 retryCount = 3, TDuration sleepDuration = TDuration::Seconds(1), TDuration sleepRandomDelta = TDuration::Zero(), + TRetryOptions(ui32 retryCount = 3, TDuration sleepDuration = TDuration::Seconds(1), TDuration sleepRandomDelta = TDuration::Zero(), TDuration sleepIncrement = TDuration::Zero(), TDuration sleepExponentialMultiplier = TDuration::Zero(), std::function<void(TDuration)> sleepFunction = [](TDuration d) { Sleep(d); }) // can't use Sleep itself due to Win compilation error : RetryCount(retryCount) , SleepDuration(sleepDuration) , SleepRandomDelta(sleepRandomDelta) - , SleepIncrement(sleepIncrement) - , SleepExponentialMultiplier(sleepExponentialMultiplier) + , SleepIncrement(sleepIncrement) + , SleepExponentialMultiplier(sleepExponentialMultiplier) , SleepFunction(sleepFunction) { } @@ -48,26 +48,26 @@ struct TRetryOptions { return *this; } - TRetryOptions& WithIncrement(TDuration sleepIncrement) { - SleepIncrement = sleepIncrement; - return *this; + TRetryOptions& WithIncrement(TDuration sleepIncrement) { + SleepIncrement = sleepIncrement; + return *this; + } + + TRetryOptions& WithExponentialMultiplier(TDuration sleepExponentialMultiplier) { + SleepExponentialMultiplier = sleepExponentialMultiplier; + return *this; } - TRetryOptions& WithExponentialMultiplier(TDuration sleepExponentialMultiplier) { - SleepExponentialMultiplier = sleepExponentialMultiplier; - return *this; - } - TRetryOptions& WithSleepFunction(std::function<void(TDuration)> sleepFunction) { SleepFunction = sleepFunction; return *this; } - // for compatibility attempt == 0 by default - TDuration GetTimeToSleep(ui32 attempt = 0) const { + // for compatibility attempt == 0 by default + TDuration GetTimeToSleep(ui32 attempt = 0) const { return SleepDuration + NRetryPrivate::AddRandomDelta(SleepRandomDelta) + NRetryPrivate::AddIncrement(attempt, SleepIncrement) + NRetryPrivate::AddExponentialMultiplier(attempt, SleepExponentialMultiplier); - } - + } + static TRetryOptions Count(ui32 retryCount) { return TRetryOptions(retryCount); } |