Skip to content

Commit

Permalink
fix: allow two chain calls with the same name to be executed simultan…
Browse files Browse the repository at this point in the history
…eously
  • Loading branch information
Bycob authored and mergify[bot] committed Sep 15, 2023
1 parent 57bed0b commit b26b5b9
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/services.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<spdlog::logger> &chain_logger,
APIData &adc, ChainData &cdata,
Expand Down Expand Up @@ -914,12 +928,12 @@ namespace dd
return 0;
}

oatpp::Object<DTO::ChainBody> chain(const APIData &ad,
const std::string &cname)
oatpp::Object<DTO::ChainBody> chain(const APIData &ad, std::string cname)
{
oatpp::Object<DTO::ChainBody> chain_dto;
try
{
cname = find_logger_name(cname);
auto chain_logger = DD_SPDLOG_LOGGER(cname);

std::chrono::time_point<std::chrono::system_clock> tstart
Expand Down Expand Up @@ -1240,11 +1254,12 @@ namespace dd
}

oatpp::Object<DTO::ChainBody>
chain(oatpp::Object<DTO::ServiceChain> input_dto, const std::string &cname)
chain(oatpp::Object<DTO::ServiceChain> input_dto, std::string cname)
{
oatpp::Object<DTO::ChainBody> out_dto;
try
{
cname = find_logger_name(cname);
auto chain_logger = DD_SPDLOG_LOGGER(cname);

std::chrono::time_point<std::chrono::system_clock> tstart
Expand Down

0 comments on commit b26b5b9

Please sign in to comment.