retry_policy.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include <util/datetime/base.h>
  3. #include <util/generic/ptr.h>
  4. namespace NYT {
  5. ////////////////////////////////////////////////////////////////////////////////
  6. /// A configuration that controls retries of a single request.
  7. struct TRetryConfig
  8. {
  9. ///
  10. /// @brief How long retries of a single YT request can go on.
  11. ///
  12. /// If this limit is reached while retry count is not yet exceeded @ref TRequestRetriesTimeout exception is thrown.
  13. TDuration RetriesTimeLimit = TDuration::Max();
  14. };
  15. /// The library uses this class to understand how to retry individual requests.
  16. class IRetryConfigProvider
  17. : public virtual TThrRefBase
  18. {
  19. public:
  20. ///
  21. /// @brief Gets retry policy for single request.
  22. ///
  23. /// CreateRetryConfig is called before ANY request.
  24. /// Returned config controls retries of this request.
  25. ///
  26. /// Must be thread safe since it can be used from different threads
  27. /// to perform internal library requests (e.g. pings).
  28. ///
  29. /// Some methods (e.g. IClient::Map) involve multiple requests to YT and therefore
  30. /// this method will be called several times during execution of single method.
  31. ///
  32. /// If user needs to limit overall retries inside long operation they might create
  33. /// retry policy that knows about overall deadline
  34. /// @ref NYT::TRetryConfig::RetriesTimeLimit taking into account that overall deadline.
  35. /// (E.g. when deadline reached it returns zero limit for retries).
  36. virtual TRetryConfig CreateRetryConfig() = 0;
  37. };
  38. ////////////////////////////////////////////////////////////////////////////////
  39. } // namespace NYT