TensorFlow Serving C++ API Documentation
retrier.h
1 /* Copyright 2017 Google Inc. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7  http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_SERVING_UTIL_RETRIER_H_
17 #define TENSORFLOW_SERVING_UTIL_RETRIER_H_
18 
19 #include <functional>
20 #include <string>
21 
22 #include "absl/status/status.h"
23 #include "tensorflow/core/lib/core/status.h"
24 
25 namespace tensorflow {
26 namespace serving {
27 
28 // Tries running 'retried_fn' once, and if it doesn't succeed, retries running
29 // the 'retried_fn' till it returns an ok status or max_num_retries are
30 // exhausted or should_retry() returns false. Each retry is attempted after an
31 // interval of 'retry_interval_micros'. The 'description' is useful for logging.
32 //
33 // Returns the status returned by the last call to 'retried_fn'.
34 absl::Status Retry(
35  const string& description, uint32 max_num_retries,
36  int64_t retry_interval_micros,
37  const std::function<absl::Status()>& retried_fn,
38  const std::function<bool(absl::Status)>& should_retry =
39  [](absl::Status status) { return true; });
40 
41 } // namespace serving
42 } // namespace tensorflow
43 
44 #endif // TENSORFLOW_SERVING_UTIL_RETRIER_H_