From b26b5b98a991457730747697891ac9a4ef9a45c6 Mon Sep 17 00:00:00 2001 From: Louis Jean Date: Fri, 15 Sep 2023 16:06:06 +0200 Subject: [PATCH] fix: allow two chain calls with the same name to be executed simultaneously --- src/services.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/services.h b/src/services.h index 4b447983d..b16598180 100644 --- a/src/services.h +++ b/src/services.h @@ -708,6 +708,20 @@ namespace dd return pred_dto; } + /** Find a logger name that does not exist yet for chain call */ + std::string find_logger_name(std::string cname) + { + int i = 1; + std::string prefix = cname; + + while (spdlog::get(cname) != nullptr) + { + i++; + cname = prefix + "-" + std::to_string(i); + } + return cname; + } + int chain_service(const std::string &cname, const std::shared_ptr &chain_logger, APIData &adc, ChainData &cdata, @@ -914,12 +928,12 @@ namespace dd return 0; } - oatpp::Object chain(const APIData &ad, - const std::string &cname) + oatpp::Object chain(const APIData &ad, std::string cname) { oatpp::Object chain_dto; try { + cname = find_logger_name(cname); auto chain_logger = DD_SPDLOG_LOGGER(cname); std::chrono::time_point tstart @@ -1240,11 +1254,12 @@ namespace dd } oatpp::Object - chain(oatpp::Object input_dto, const std::string &cname) + chain(oatpp::Object input_dto, std::string cname) { oatpp::Object out_dto; try { + cname = find_logger_name(cname); auto chain_logger = DD_SPDLOG_LOGGER(cname); std::chrono::time_point tstart