Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion async_grpc/retry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ RetryIndicator CreateLimitedRetryIndicator(int max_attempts) {
};
}

RetryIndicator CreateLimitedRetryIndicator(
int max_attempts, const std::set<::grpc::StatusCode>& unrecoverable_codes) {
return [max_attempts, unrecoverable_codes](int failed_attempts,
const ::grpc::Status& status) {
return (failed_attempts < max_attempts) &&
!unrecoverable_codes.count(status.error_code());
};
}

RetryIndicator CreateUnlimitedRetryIndicator() {
return [](int failed_attempts, const ::grpc::Status &status) { return true; };
}
Expand All @@ -48,7 +57,7 @@ RetryIndicator CreateUnlimitedRetryIndicator(
const std::set<::grpc::StatusCode> &unrecoverable_codes) {
return
[unrecoverable_codes](int failed_attempts, const ::grpc::Status &status) {
return unrecoverable_codes.count(status.error_code()) <= 0;
return !unrecoverable_codes.count(status.error_code());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this because it didn't make sense, count() returns either 1 or 0 for a set.

We can change it to count == 0 if you prefer that style.

};
}

Expand Down Expand Up @@ -80,6 +89,20 @@ RetryStrategy CreateUnlimitedConstantDelayStrategy(Duration delay) {
CreateConstantDelayCalculator(delay));
}

RetryStrategy CreateLimitedConstantDelayStrategy(Duration delay,
int max_attempts) {
return CreateRetryStrategy(CreateLimitedRetryIndicator(max_attempts),
CreateConstantDelayCalculator(delay));
}

RetryStrategy CreateLimitedConstantDelayStrategy(
Duration delay, int max_attempts,
const std::set<::grpc::StatusCode>& unrecoverable_codes) {
return CreateRetryStrategy(
CreateLimitedRetryIndicator(max_attempts, unrecoverable_codes),
CreateConstantDelayCalculator(delay));
}

RetryStrategy CreateUnlimitedConstantDelayStrategy(
Duration delay, const std::set<::grpc::StatusCode> &unrecoverable_codes) {
return CreateRetryStrategy(CreateUnlimitedRetryIndicator(unrecoverable_codes),
Expand Down
7 changes: 7 additions & 0 deletions async_grpc/retry.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ RetryStrategy CreateRetryStrategy(RetryIndicator retry_indicator,
RetryDelayCalculator retry_delay_calculator);

RetryIndicator CreateLimitedRetryIndicator(int max_attempts);
RetryIndicator CreateLimitedRetryIndicator(
int max_attempts, const std::set<::grpc::StatusCode>& unrecoverable_codes);
RetryIndicator CreateUnlimitedRetryIndicator();
RetryIndicator CreateUnlimitedRetryIndicator(
const std::set<::grpc::StatusCode> &unrecoverable_codes);
Expand All @@ -47,6 +49,11 @@ RetryDelayCalculator CreateConstantDelayCalculator(Duration delay);
RetryStrategy CreateLimitedBackoffStrategy(Duration min_delay,
float backoff_factor,
int max_attempts);
RetryStrategy CreateLimitedConstantDelayStrategy(Duration delay,
int max_attempts);
RetryStrategy CreateLimitedConstantDelayStrategy(
Duration delay, int max_attempts,
const std::set<::grpc::StatusCode>& unrecoverable_codes);
RetryStrategy CreateUnlimitedConstantDelayStrategy(Duration delay);
RetryStrategy CreateUnlimitedConstantDelayStrategy(
Duration delay, const std::set<::grpc::StatusCode> &unrecoverable_codes);
Expand Down