Skip to content

Commit

Permalink
Refactored If-Statements
Browse files Browse the repository at this point in the history
Example:

Before: 
if (st.OK()) {
        if (response.code() == 0) {
            if (response.has_job()) {
                job_info->CopyFrom(response.job());
            }
        }
        return {response.code(), response.msg()};
    } 

*****************************************

After:

if (st.OK() && response.code() == 0 && response.has_job()) {
    job_info->CopyFrom(response.job());
    return {response.code(), response.msg()};
}
  • Loading branch information
vedevpatel authored Dec 12, 2023
1 parent 0c2592d commit f31ea37
Showing 1 changed file with 32 additions and 66 deletions.
98 changes: 32 additions & 66 deletions src/client/taskmanager_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ ::openmldb::base::Status TaskManagerClient::ShowJobs(bool only_unfinished, int j
auto st = client_.SendRequestSt(&::openmldb::taskmanager::TaskManagerServer_Stub::ShowJobs, &request, &response,
job_timeout, 1);
// if ok, cntl won't failed, only check repsonse
if (st.OK()) {
if (response.code() == 0) {
for (int32_t i = 0; i < response.jobs_size(); i++) {
::openmldb::taskmanager::JobInfo job_info;
job_info.CopyFrom(response.jobs(i));
job_infos->push_back(job_info);
if (st.OK() && response.code() == 0) {
for (int32_t i = 0; i < response.jobs_size(); i++) {
::openmldb::taskmanager::JobInfo job_info;
job_info.CopyFrom(response.jobs(i));
job_infos->push_back(job_info);
}
}
return {response.code(), response.msg()};
}
return st;
Expand All @@ -54,12 +52,8 @@ ::openmldb::base::Status TaskManagerClient::ShowJob(const int id, int job_timeou
auto st = client_.SendRequestSt(&::openmldb::taskmanager::TaskManagerServer_Stub::ShowJob, &request, &response,
job_timeout, 1);

if (st.OK()) {
if (response.code() == 0) {
if (response.has_job()) {
job_info->CopyFrom(response.job());
}
}
if (st.OK() && response.code() == 0 && response.has_job()) {
job_info->CopyFrom(response.job());
return {response.code(), response.msg()};
}

Expand All @@ -76,12 +70,8 @@ ::openmldb::base::Status TaskManagerClient::StopJob(const int id, int job_timeou
auto st = client_.SendRequestSt(&::openmldb::taskmanager::TaskManagerServer_Stub::StopJob, &request, &response,
job_timeout, 1);

if (st.OK()) {
if (response.code() == 0) {
if (response.has_job()) {
job_info->CopyFrom(response.job());
}
}
if (st.OK() && response.code() == 0 && response.has_job()) {
job_info->CopyFrom(response.job());
return {response.code(), response.msg()};
}
return st;
Expand All @@ -103,10 +93,8 @@ ::openmldb::base::Status TaskManagerClient::RunBatchSql(const std::string& sql,
auto st = client_.SendRequestSt(&::openmldb::taskmanager::TaskManagerServer_Stub::RunBatchSql, &request, &response,
job_timeout, 1);

if (st.OK()) {
if (response.code() == 0) {
*output = response.output();
}
if (st.OK() && response.code() == 0) {
*output = response.output();
return {response.code(), response.msg()};
}
return st;
Expand All @@ -130,12 +118,8 @@ ::openmldb::base::Status TaskManagerClient::RunBatchAndShow(const std::string& s
auto st = client_.SendRequestSt(&::openmldb::taskmanager::TaskManagerServer_Stub::RunBatchAndShow, &request,
&response, job_timeout, 1);

if (st.OK()) {
if (response.code() == 0) {
if (response.has_job()) {
job_info->CopyFrom(response.job());
}
}
if (st.OK() && response.code() == 0 && response.has_job()) {

Check warning on line 121 in src/client/taskmanager_client.cc

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] reported by reviewdog 🐶 Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] Raw Output: src/client/taskmanager_client.cc:121: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
job_info->CopyFrom(response.job());
return {response.code(), response.msg()};
}
return st;
Expand All @@ -159,12 +143,8 @@ ::openmldb::base::Status TaskManagerClient::ImportOnlineData(const std::string&
auto st = client_.SendRequestSt(&::openmldb::taskmanager::TaskManagerServer_Stub::ImportOnlineData, &request,
&response, job_timeout, 1);

if (st.OK()) {
if (response.code() == 0) {
if (response.has_job()) {
job_info->CopyFrom(response.job());
}
}
if (st.OK() && response.code() == 0 && response.has_job()) {
job_info->CopyFrom(response.job());

Check warning on line 147 in src/client/taskmanager_client.cc

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] reported by reviewdog 🐶 Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] Raw Output: src/client/taskmanager_client.cc:147: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
return {response.code(), response.msg()};
}
return st;
Expand All @@ -188,12 +168,8 @@ ::openmldb::base::Status TaskManagerClient::ImportOfflineData(const std::string&
auto st = client_.SendRequestSt(&::openmldb::taskmanager::TaskManagerServer_Stub::ImportOfflineData, &request,
&response, job_timeout, 1);

if (st.OK()) {
if (response.code() == 0) {
if (response.has_job()) {
job_info->CopyFrom(response.job());
}
}
if (st.OK() && response.code() == 0 && response.has_job()) {
job_info->CopyFrom(response.job());
return {response.code(), response.msg()};
}
return st;
Expand All @@ -217,12 +193,8 @@ ::openmldb::base::Status TaskManagerClient::ExportOfflineData(const std::string&
auto st = client_.SendRequestSt(&::openmldb::taskmanager::TaskManagerServer_Stub::ExportOfflineData, &request,
&response, job_timeout, 1);

if (st.OK()) {
if (response.code() == 0) {
if (response.has_job()) {
job_info->CopyFrom(response.job());
}
}
if (st.OK() && response.code() == 0 && response.has_job()) {
job_info->CopyFrom(response.job());
return {response.code(), response.msg()};
}
return st;
Expand Down Expand Up @@ -254,12 +226,8 @@ std::string TaskManagerClient::GetJobLog(const int id, int job_timeout, ::openml
auto st = client_.SendRequestSt(&::openmldb::taskmanager::TaskManagerServer_Stub::GetJobLog, &request, &response,
job_timeout, 1);

if (st.OK()) {
if (response.code() == 0) {
if (response.has_log()) {
return response.log();
}
}
if (st.OK() && response.code() == 0 && response.has_log()) {

Check warning on line 229 in src/client/taskmanager_client.cc

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] reported by reviewdog 🐶 Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] Raw Output: src/client/taskmanager_client.cc:229: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
return response.log();
status->code = response.code();
status->msg = response.msg();
return "";
Expand All @@ -279,13 +247,12 @@ ::openmldb::base::Status TaskManagerClient::CreateFunction(const std::shared_ptr
request.mutable_fun()->CopyFrom(*fun);
auto st = client_.SendRequestSt(&::openmldb::taskmanager::TaskManagerServer_Stub::CreateFunction, &request,
&response, job_timeout, 1);
if (st.OK()) {
if (response.code() == 0) {
return {};
} else {
// base::ReturnCode
return {response.code(), response.msg()};
}
if (st.OK() && response.code() == 0) {

Check warning on line 251 in src/client/taskmanager_client.cc

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] reported by reviewdog 🐶 Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] Raw Output: src/client/taskmanager_client.cc:251: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]

Check warning on line 251 in src/client/taskmanager_client.cc

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] reported by reviewdog 🐶 Redundant blank line at the start of a code block should be deleted. [whitespace/blank_line] [2] Raw Output: src/client/taskmanager_client.cc:251: Redundant blank line at the start of a code block should be deleted. [whitespace/blank_line] [2]
return {};
} else {
// base::ReturnCode
return {response.code(), response.msg()};
}
return st;
}
Expand All @@ -296,12 +263,11 @@ ::openmldb::base::Status TaskManagerClient::DropFunction(const std::string& name
::openmldb::taskmanager::DropFunctionResponse response;
auto st = client_.SendRequestSt(&::openmldb::taskmanager::TaskManagerServer_Stub::DropFunction, &request, &response,
job_timeout, 1);
if (st.OK()) {
if (response.code() == 0) {
return {};
} else {
return {response.code(), response.msg()};
}
if (st.OK() && response.code() == 0) {

Check warning on line 267 in src/client/taskmanager_client.cc

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] reported by reviewdog 🐶 Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] Raw Output: src/client/taskmanager_client.cc:267: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]

Check warning on line 267 in src/client/taskmanager_client.cc

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] reported by reviewdog 🐶 Redundant blank line at the start of a code block should be deleted. [whitespace/blank_line] [2] Raw Output: src/client/taskmanager_client.cc:267: Redundant blank line at the start of a code block should be deleted. [whitespace/blank_line] [2]
return {};
else {

Check warning on line 269 in src/client/taskmanager_client.cc

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] reported by reviewdog 🐶 If an else has a brace on one side, it should have it on both [readability/braces] [5] Raw Output: src/client/taskmanager_client.cc:269: If an else has a brace on one side, it should have it on both [readability/braces] [5]
return {response.code(), response.msg()};

Check warning on line 270 in src/client/taskmanager_client.cc

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] reported by reviewdog 🐶 Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] Raw Output: src/client/taskmanager_client.cc:270: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
}
return st;
}
Expand Down

0 comments on commit f31ea37

Please sign in to comment.