init.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. ///
  3. /// @file yt/cpp/mapreduce/interface/init.h
  4. ///
  5. /// Initialization functions of YT Wrapper.
  6. #include <yt/cpp/mapreduce/interface/wait_proxy.h>
  7. #include <util/generic/fwd.h>
  8. #include <functional>
  9. namespace NYT {
  10. ////////////////////////////////////////////////////////////////////////////////
  11. /// Options for @ref NYT::Initialize() and @ref NYT::JoblessInitialize() functions
  12. struct TInitializeOptions
  13. {
  14. using TSelf = TInitializeOptions;
  15. ///
  16. /// @brief Override waiting functions for YT Wrapper.
  17. ///
  18. /// This options allows to override functions used by this library to wait something.
  19. FLUENT_FIELD_DEFAULT(::TIntrusivePtr<IWaitProxy>, WaitProxy, nullptr);
  20. ///
  21. /// @brief Enable/disable cleanup when program execution terminates abnormally.
  22. ///
  23. /// When set to true, library will abort all active transactions and running operations when program
  24. /// terminates on error or signal.
  25. FLUENT_FIELD_DEFAULT(bool, CleanupOnTermination, false);
  26. ///
  27. /// @brief Set callback to be called before exit() in job mode.
  28. ///
  29. /// Provided function will be called just before exit() when program is started in job mode.
  30. /// This might be useful for shutting down libraries that are used inside operations.
  31. ///
  32. /// NOTE: Keep in mind that inside job execution environment differs from client execution environment.
  33. /// So JobOnExitFunction should not depend on argc/argv environment variables etc.
  34. FLUENT_FIELD_OPTION(std::function<void()>, JobOnExitFunction);
  35. };
  36. ///
  37. /// @brief Performs basic initialization (logging, termination handlers, etc).
  38. ///
  39. /// This function never switches to job mode.
  40. void JoblessInitialize(const TInitializeOptions& options = TInitializeOptions());
  41. ///
  42. /// @brief Performs basic initialization and switches to a job mode if required.
  43. ///
  44. /// This function performs basic initialization (it sets up logging reads the config, etc) and checks if binary is launched
  45. /// on YT machine inside a job. If latter is true this function launches proper job and after job is done it calls exit().
  46. ///
  47. /// This function must be called if application starts any operation.
  48. /// This function must be called immediately after entering main() function before any argument parsing is done.
  49. void Initialize(int argc, const char **argv, const TInitializeOptions &options = TInitializeOptions());
  50. /// Similar to @ref NYT::Initialize(int, const char**, const TInitializeOptions&)
  51. void Initialize(int argc, char **argv, const TInitializeOptions &options = TInitializeOptions());
  52. /// Similar to @ref NYT::Initialize(int, const char**, const TInitializeOptions&)
  53. void Initialize(const TInitializeOptions &options = TInitializeOptions());
  54. ////////////////////////////////////////////////////////////////////////////////
  55. } // namespace NYT