From de1876a182f18397593b1d3c82305fe4e2f6add9 Mon Sep 17 00:00:00 2001 From: Chris Pinkenburg Date: Mon, 1 Jan 2024 11:15:46 -0500 Subject: [PATCH 1/2] change retry mechanics --- src/realwrapper.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/realwrapper.cpp b/src/realwrapper.cpp index 25c4c6f..485249e 100644 --- a/src/realwrapper.cpp +++ b/src/realwrapper.cpp @@ -1,5 +1,7 @@ #include +#include + namespace nopayloadclient { RealWrapper::RealWrapper(const json& config) { @@ -10,7 +12,8 @@ RealWrapper::RealWrapper(const json& config) { } void RealWrapper::sleep(int retry_number) { - int n_sleep = int(std::exp(retry_number)); + srand(time(0)); + int n_sleep = rand()%100+1; // add random sleep 1-100 secs logging::debug("sleeping for " + std::to_string(n_sleep) + " seconds before retrying..."); std::this_thread::sleep_for(std::chrono::seconds(n_sleep)); } @@ -69,4 +72,4 @@ json CurlRequest::parseResponse() { return response; } -} \ No newline at end of file +} From 71e3b4ec4d5d9902913b492eb3847ecc6c66245f Mon Sep 17 00:00:00 2001 From: Chris Pinkenburg Date: Fri, 5 Jan 2024 14:21:30 -0500 Subject: [PATCH 2/2] check if directory is created before committing --- src/nopayloadclient.cpp | 2 +- src/plhandler.cpp | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/nopayloadclient.cpp b/src/nopayloadclient.cpp index 03bc6ae..cf82ba7 100644 --- a/src/nopayloadclient.cpp +++ b/src/nopayloadclient.cpp @@ -266,8 +266,8 @@ json NoPayloadClient::makeResp(T msg) { void NoPayloadClient::insertPayload(Payload &pl, IOV &iov) { prepareInsertIov(pl); pl_handler_.prepareUploadFile(pl); - insertIov(pl, iov); pl_handler_.uploadFile(pl); + insertIov(pl, iov); } void NoPayloadClient::prepareInsertIov(Payload &pl) { diff --git a/src/plhandler.cpp b/src/plhandler.cpp index 9902e96..4576e35 100644 --- a/src/plhandler.cpp +++ b/src/plhandler.cpp @@ -73,7 +73,12 @@ void PLHandler::checkRemoteDirExists() { void PLHandler::createDirectory(const string& path){ if (!fs::is_directory(path) || !fs::exists(path)) { - fs::create_directories(path); + try{ + fs::create_directories(path); + } + catch(...){ + throw BaseException("remote payload directory "+path+" could not be created"); + } } } @@ -85,7 +90,10 @@ void PLHandler::prepareUploadFile(const Payload& pl) { void PLHandler::copyFile(const string& local_url, const string& remote_url) { if (!fs::exists(remote_url)) { - fs::copy_file(local_url, remote_url); + if (! fs::copy_file(local_url, remote_url)) + { + throw BaseException("could not copy "+local_url+" to "+remote_url); + } } }