def success(self, result): Service.update_task(task_id=self.task_id, status=Service.STATUS_SUCCESS) for ip in self.hosts: Service.update_node(node_id=self._node_map[ip], status=Service.STATUS_SUCCESS)
def failed(self, error): err_json = dict(msg=str(error)) #check whether success node exist node_list = Service.check_task(task_id=str(self.task_id)) successflag =False for node in node_list: if node.status==2: successflag=True break # update task if successflag: Service.update_task(task_id=self.task_id, status=Service.STATUS_PartlySuccess, err=json.dumps(err_json)) else: Service.update_task(task_id=self.task_id, status=Service.STATUS_FAILED, err=json.dumps(err_json))
def stop_task(): try: #read http params req_json = request.get_json(force=True, silent=True) if req_json is None: raise JsonEncodeException global_id = request.headers["X-CORRELATION-ID"] if global_id is None: return_failed(-1, "X-CORRELATION-ID is Empty"), 400 source = request.headers["X-SOURCE"] if source is None: return_failed(-1, "X-SOURCE is Empty"), 400 Logger.debug("Stop request json:" + json.dumps(req_json) + str(global_id)) task_id = conform_param(req_json, "id", param_type=int, allowNone=True) task_name = conform_param(req_json, "name", param_type=basestring, allowNone=True) #stop task by id if task_id is None: if task_name is None: raise ParamErrorException("key task_id/task_name not found") else: task = Service.get_task_by_name(task_name) if task is None: return return_failed(-1, "task not found"), 404 task_id = task.id Worker.stop(str(task_id)) # update task status Service.update_task(task_id, status=Service.STATUS_STOPPED) return return_success(), 200 except JsonEncodeException: Logger.error("try stop_task exception --------------@") return return_failed(-1, "json encode error"), 400 except Exception as e: Logger.error("try stop_task exception --------------> %s" % (str(e))) return return_failed(-1, e.message), 400