| 1728 | } |
| 1729 | |
| 1730 | int NameServerImpl::UpdateTask(const std::list<std::shared_ptr<OPData>>& op_list, const std::string& endpoint, |
| 1731 | const std::string& msg, bool is_recover_op, ::fedb::api::TaskStatusResponse& response) { |
| 1732 | if (op_list.empty()) { |
| 1733 | return -1; |
| 1734 | } |
| 1735 | std::shared_ptr<OPData> op_data = op_list.front(); |
| 1736 | if (op_data->task_list_.empty()) { |
| 1737 | return -1; |
| 1738 | } |
| 1739 | // update task status |
| 1740 | std::shared_ptr<Task> task = op_data->task_list_.front(); |
| 1741 | if (task->task_info_->status() != ::fedb::api::kDoing) { |
| 1742 | return -1; |
| 1743 | } |
| 1744 | bool has_op_task = false; |
| 1745 | for (int idx = 0; idx < response.task_size(); idx++) { |
| 1746 | if (op_data->op_info_.op_id() == response.task(idx).op_id() && |
| 1747 | task->task_info_->task_type() == response.task(idx).task_type()) { |
| 1748 | has_op_task = true; |
| 1749 | if (response.task(idx).status() != ::fedb::api::kInited) { |
| 1750 | if (!task->sub_task_.empty()) { |
| 1751 | for (auto& sub_task : task->sub_task_) { |
| 1752 | if (sub_task->task_info_->has_endpoint() && sub_task->task_info_->endpoint() == endpoint && |
| 1753 | sub_task->task_info_->status() != response.task(idx).status()) { |
| 1754 | PDLOG(INFO, |
| 1755 | "update sub task status from[%s] to[%s]. " |
| 1756 | "op_id[%lu], task_type[%s]", |
| 1757 | ::fedb::api::TaskStatus_Name(sub_task->task_info_->status()).c_str(), |
| 1758 | ::fedb::api::TaskStatus_Name(response.task(idx).status()).c_str(), |
| 1759 | response.task(idx).op_id(), |
| 1760 | ::fedb::api::TaskType_Name(sub_task->task_info_->task_type()).c_str()); |
| 1761 | sub_task->task_info_->set_status(response.task(idx).status()); |
| 1762 | if (response.task(idx).status() == ::fedb::api::kFailed) { |
| 1763 | task->task_info_->set_status(::fedb::api::kFailed); |
| 1764 | PDLOG(INFO, |
| 1765 | "update task status from[%s] " |
| 1766 | "to[kFailed]. op_id[%lu], task_type[%s]", |
| 1767 | ::fedb::api::TaskStatus_Name(task->task_info_->status()).c_str(), |
| 1768 | response.task(idx).op_id(), |
| 1769 | ::fedb::api::TaskType_Name(task->task_info_->task_type()).c_str()); |
| 1770 | } |
| 1771 | break; |
| 1772 | } |
| 1773 | } |
| 1774 | } else if (task->task_info_->status() != response.task(idx).status()) { |
| 1775 | PDLOG(INFO, |
| 1776 | "update task status from[%s] to[%s]. op_id[%lu], " |
| 1777 | "task_type[%s]", |
| 1778 | ::fedb::api::TaskStatus_Name(task->task_info_->status()).c_str(), |
| 1779 | ::fedb::api::TaskStatus_Name(response.task(idx).status()).c_str(), |
| 1780 | response.task(idx).op_id(), |
| 1781 | ::fedb::api::TaskType_Name(task->task_info_->task_type()).c_str()); |
| 1782 | task->task_info_->set_status(response.task(idx).status()); |
| 1783 | } |
| 1784 | } |
| 1785 | break; |
| 1786 | } |
| 1787 | } |