Skip to content

Commit

Permalink
Fix upgrade bug (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCode2012 authored Mar 21, 2022
1 parent 1a5953a commit 7eaaeda
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/app/http/ApiHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,21 @@ void ApiHandler::http_handler(beast::string_view /*doc_root*/,
cur_path = urlendpoint.base + "/upgrade/metadata";
if (req_route.size() == cur_path.size() && req_route.compare(cur_path) == 0)
{
if (UPGRADE_STATUS_COMPLETE != ed->get_upgrade_status())
upgrade_status_t upgrade_status = ed->get_upgrade_status();
if (UPGRADE_STATUS_COMPLETE != upgrade_status)
{
json::JSON ret_body;
ret_body[HTTP_STATUS_CODE] = 502;
ret_body[HTTP_MESSAGE] = "Metadata is still collecting!";
if (UPGRADE_STATUS_NONE == upgrade_status)
{
// Set timeout http status code
ret_body[HTTP_STATUS_CODE] = 408;
ret_body[HTTP_MESSAGE] = "Upgrade timeout for old sworker!";
}
else
{
ret_body[HTTP_STATUS_CODE] = 502;
ret_body[HTTP_MESSAGE] = "Metadata is still collecting!";
}
res.result(ret_body[HTTP_STATUS_CODE].ToInt());
res.body() = ret_body.dump();
}
Expand Down
10 changes: 8 additions & 2 deletions src/app/process/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,19 @@ bool upgrade_try_restore()
{
// Try to get metadata
res_meta = client->Get(p_config->base_url + "/upgrade/metadata", "", headers);
if ((int)res_meta.result() != 200)
int res_code = (int)res_meta.result();
if (res_code != 200)
{
if ((int)res_meta.result() == 404)
if (res_code == 404)
{
p_log->err("Get upgrade data failed!Old sWorker is not running!\n");
return false;
}
if (res_code == 408)
{
p_log->err("Upgrade timeout for old sworker, will retry later.\n");
return false;
}
if (res_meta.body().compare(err_msg) != 0)
{
p_log->info("Old version Message:%s\n", res_meta.body().c_str());
Expand Down

0 comments on commit 7eaaeda

Please sign in to comment.