Skip to content

Commit

Permalink
added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nedvedba committed Sep 19, 2024
1 parent aca966d commit 5f278e8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/server/TaskWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ void TaskWorker::workerThread(LogContext log_context) {

err_msg.clear();
first = true;
// This value is increased everytime a failed db connection happens and is
// used to prevent the relevant logging from printing as fast as this while
// loop can run
db_connection_backoff = 1;

while (true) {
Expand Down Expand Up @@ -136,6 +139,7 @@ void TaskWorker::workerThread(LogContext log_context) {
}
}

// Set back to default since a db connection was successfully established
db_connection_backoff = 1;
} catch (TraceException &e) {
err_msg = e.toString();
Expand All @@ -145,7 +149,14 @@ void TaskWorker::workerThread(LogContext log_context) {
<< " task_id is " << m_task->task_id
<< " cmd is " << cmd);

// Detect, log, and backoff the db connection until it can successfully be established
if (err_msg.find("SDMS DB interface failed") != std::string::npos) {
DL_INFO(log_context, "Task worker "
<< id() << " exception: " << err_msg
<< " backoff is set to " << db_connection_backoff
<< " task_id is " << m_task->task_id
<< " cmd is " << cmd);

int sleep_time = db_connection_backoff;
db_connection_backoff = min(db_connection_backoff * 2, 60);
sleep(sleep_time);
Expand Down

0 comments on commit 5f278e8

Please sign in to comment.