Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile with optimization #12

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/nopayloadclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,14 @@ json NoPayloadClient::makeResp(T msg) {
return {{"code", 0}, {"msg", msg}};
}

template json NoPayloadClient::makeResp(json);

// Private
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) {
Expand Down
12 changes: 10 additions & 2 deletions src/plhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}

Expand All @@ -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);
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/realwrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <nopayloadclient/realwrapper.hpp>

#include <cstdlib>
#include <random>

namespace nopayloadclient {

Expand All @@ -13,8 +14,9 @@ RealWrapper::RealWrapper(const json& config) {
}

void RealWrapper::sleep(int retry_number) {
srand(time(0));
int n_sleep = rand()%(retry_sleep_mean_*2)+1; // add random sleep
std::random_device rd;
std::uniform_int_distribution<int> dist(1, retry_sleep_mean_*2);
int n_sleep = dist(rd); // add random sleep
logging::debug("sleeping for " + std::to_string(n_sleep) + " seconds before retrying...");
std::this_thread::sleep_for(std::chrono::seconds(n_sleep));
}
Expand Down