|
@@ -10,6 +10,7 @@
|
|
|
// It deliberately holds the only code here that links vectorapi_core and the
|
|
// It deliberately holds the only code here that links vectorapi_core and the
|
|
|
// database client, which is what keeps run_service testable on a host where
|
|
// database client, which is what keeps run_service testable on a host where
|
|
|
// that client cannot compile at all (CLAUDE.md).
|
|
// that client cannot compile at all (CLAUDE.md).
|
|
|
|
|
+#include "db_await.hpp"
|
|
|
#include "db_gateway.hpp"
|
|
#include "db_gateway.hpp"
|
|
|
#include "errors.hpp"
|
|
#include "errors.hpp"
|
|
|
#include "function_env.hpp"
|
|
#include "function_env.hpp"
|
|
@@ -529,7 +530,14 @@ int main(int argc, char** argv) {
|
|
|
|
|
|
|
|
svapi::DbGateway db(cfg.dbAddress);
|
|
svapi::DbGateway db(cfg.dbAddress);
|
|
|
spdlog::info("connecting to smartbotic-database at {}", cfg.dbAddress);
|
|
spdlog::info("connecting to smartbotic-database at {}", cfg.dbAddress);
|
|
|
- for (int i = 0; i < 30 && !db.connect(); ++i) std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
|
+ // Bounded by WALL TIME, not by an attempt count - see db_await.hpp. 60 s
|
|
|
|
|
+ // sits comfortably inside systemd's 90 s TimeoutStartSec, so an unreachable
|
|
|
|
|
+ // database produces a clean diagnostic and exit 1 rather than being killed
|
|
|
|
|
+ // mid-loop with a misleading "start operation timed out".
|
|
|
|
|
+ svapi::awaitConnectable([&db] { return db.connect(); },
|
|
|
|
|
+ [] { return std::chrono::steady_clock::now(); },
|
|
|
|
|
+ [](std::chrono::milliseconds d) { std::this_thread::sleep_for(d); },
|
|
|
|
|
+ std::chrono::seconds(60), std::chrono::seconds(1));
|
|
|
if (!db.healthy()) { spdlog::error("database not reachable at {}", cfg.dbAddress); return 1; }
|
|
if (!db.healthy()) { spdlog::error("database not reachable at {}", cfg.dbAddress); return 1; }
|
|
|
|
|
|
|
|
svapi::FunctionRegistry registry(db);
|
|
svapi::FunctionRegistry registry(db);
|