Files
metabuilder/dbal/cpp/src/util/backoff.cpp
copilot-swe-agent[bot] b309b20ccc Implement C++ daemon with CMake, Ninja build system
Created complete C++ implementation:
- Core library (client, errors, capabilities)
- Query engine (AST, builder, normalizer)
- Utilities (UUID generation, exponential backoff)
- SQLite adapter and connection pool
- Daemon server with security manager
- Unit, integration, and conformance tests

Build system:
- CMakeLists.txt with optional Conan dependencies
- Renamed build assistant to .cjs for ES module compatibility
- Fixed conanfile.txt format for Conan 2.x
- All tests passing, daemon runs successfully

Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
2025-12-24 22:46:00 +00:00

38 lines
863 B
C++

#include <thread>
#include <chrono>
#include <algorithm>
namespace dbal {
namespace util {
class ExponentialBackoff {
public:
ExponentialBackoff(int initial_ms = 100, int max_ms = 30000, double multiplier = 2.0)
: current_ms_(initial_ms), max_ms_(max_ms), multiplier_(multiplier), attempt_(0) {}
void sleep() {
std::this_thread::sleep_for(std::chrono::milliseconds(current_ms_));
// Increase backoff time for next attempt
current_ms_ = std::min(static_cast<int>(current_ms_ * multiplier_), max_ms_);
attempt_++;
}
void reset() {
current_ms_ = 100;
attempt_ = 0;
}
int currentMs() const { return current_ms_; }
int attempt() const { return attempt_; }
private:
int current_ms_;
int max_ms_;
double multiplier_;
int attempt_;
};
}
}