bind_in_range.cpp 828 B

123456789101112131415161718192021222324252627
  1. #include "bind_in_range.h"
  2. #include <yql/essentials/utils/log/log.h>
  3. #include <util/datetime/base.h>
  4. namespace NYql {
  5. TVector<NBus::TBindResult> BindInRange(TRangeWalker<int>& portWalker) {
  6. const int cyclesLimit = 3;
  7. const int rangeSize = portWalker.GetRangeSize();
  8. const auto cycleDelay = TDuration::Seconds(3);
  9. for (int cycle = 0; cycle < cyclesLimit; ++cycle) {
  10. for (int i = 0; i < rangeSize; ++i) {
  11. try {
  12. return NBus::BindOnPort(portWalker.MoveToNext(), false).second;
  13. } catch (const TSystemError&) {
  14. YQL_LOG(DEBUG) << CurrentExceptionMessage();
  15. }
  16. }
  17. Sleep(cycleDelay);
  18. }
  19. ythrow yexception() << "Unable to bind within port range [" << portWalker.GetStart() << ", " << portWalker.GetFinish() << "]";
  20. }
  21. }