Beispiel #1
0
 def _generate_err_taskbatchback(self, tb: IscoutBtaskBack):
     """返回控制端内部处理错误信息到中心"""
     try:
         tb._cmdrcvmsg = "内部错误:{}".format(tb._cmdrcvmsg)
         tb.cmdstatus = ECommandStatus.Failed
         if not OutputManagement.output(tb):
             self._logger.error(
                 "Generate error IscoutBtaskBack to center error:\ndata:{}\ntaskid:{}\nbatchid:{}\nerror:{}"
                 .format(tb.inputdata.name, tb._taskid, tb._batchid,
                         traceback.format_exc()))
     except Exception:
         self._logger.error(
             "Generate error IscoutBtaskBack to center error:\ndata:{}\ntaskid:{}\nbatchid:{}\nerror:{}"
             .format(tb.inputdata.name, tb._taskid, tb._batchid,
                     traceback.format_exc()))
Beispiel #2
0
    def _deal_data_back(self, tb: IscoutBtaskBack) -> bool:
        """处理TaskBatchBack数据"""
        # ==================
        # 更新指定的子任务的cmdstatus命令状态等字段
        # 综合判断总任务是否完成或结束,
        # 返回总任务完成进度或总任务最终结果

        # 当总任务下的所有子任务的命令状态均为以下枚举值时
        # Failed/Succeed/Cancelled/Timeout
        # 判定为总任务已结束

        # 子任务状态为 NeedSmsCode 时,需要在数据库添加
        # 标记,以确认中心是否收到消息并下发了验证码,若长时间
        # 未收到中心的验证码,且也未收到来自采集端的任务超时错误,
        # 需要控制端进行超时处理(此时认为采集端的此条任务挂了?)
        # ==================

        res: bool = False

        # 更新数据库子任务状态
        currperiodnum = tb.periodnum
        with self._dbmanager.get_automic_locker(
                EDBAutomic.ReduplicateIScoutTask):
            task: IscoutTask = self._dbmanager.get_iscout_batch_task(
                tb._platform, tb._taskid, tb._batchid)
            if task is None:  # 没查到,就是竟然凭空来了一个back
                self._logger.warn(
                    "No task find for IscoutTaskBack: taskid={}, batchid={}".
                    format(tb._taskid, tb._batchid))
                return res

        if tb.periodnum < task.periodnum:
            # self._logger.error(
            #     "IScoutBTaskBack periodnum({}) < task.periodnum({}) in db:\ntaskid:{}\nbatchid:{}"
            #         .format(tb.periodnum, task.periodnum, task.taskid,
            #                 task.batchid))
            # return res
            # 容错处理,更正client返回的taskback里的周期数periodnom
            self._logger.warn(
                "IScoutBTaskBack periodnum({}) < task.periodnum({}) in db, corrected it:\ntaskid:{}\nbatchid:{}"
                .format(tb.periodnum, task.periodnum, task.taskid,
                        task.batchid))
            tb.periodnum = task.periodnum

        # 只有当back的sequence>task的sequence才去更新
        if tb._sequence > task._sequence:
            if not self._deal_equal_period(tb, task):
                return res

        # 置回当前周期数
        tb.periodnum = currperiodnum
        # 回传子任务回馈文件
        if not OutputManagement.output(tb):
            tb._cmdrcvmsg = "输出IScoutTask子任务回馈数据失败"
            self._logger.error(
                "Output IScoutBatchTaskBack file to center failed:\ndata:{}\ntaskid:{}\nbatchid:{}"
                .format(tb.inputdata.name, tb._taskid, tb._batchid))
            return res

        # 计算当前子任务的 elapsed
        task.elapsed += tb.elapsed

        # 顺利跑到这里,子任务处理就是成功的了
        tb.ok = True
        self._logger.info(
            "IScoutBatchTaskBack dealt [{} {}]:\ndata:{}\ntaskid:{}\nbatchid:{}\nperiodnum:{}"
            .format(tb.cmdstatus.name, tb.progress, tb.inputdata.name,
                    tb._taskid, tb._batchid, currperiodnum))

        self._tbqueue.put(task)
        res = True
        return res
Beispiel #3
0
    def _deal_equal_period(self, tb: IscoutBtaskBack,
                           task: IscoutTask) -> bool:
        res: bool = False
        try:
            # 查询对应的总任务对象
            # 子任务是这些状态,那么总任务的 batchcompletecount+=1
            # 把当前IScouTBatchTask子任务查出来
            if tb._cmdstatus == ECommandStatus.Failed or \
                    tb._cmdstatus == ECommandStatus.Succeed or \
                    tb._cmdstatus == ECommandStatus.Timeout or \
                    tb._cmdstatus == ECommandStatus.Cancelled:
                tb.progress = 1
                if not self._dbmanager.is_iscoutbtask_batchcompletecount_increaced(
                        tb._platform, tb._taskid, tb._batchid):
                    if not self._dbmanager.increace_iscouttask_batch_complete_count(
                            tb._platform, tb._taskid, tb._batchid):
                        tb._cmdrcvmsg = "IScout子任务完成数量增加到数据库失败"
                        self._logger.error(
                            "Increace IScoutTask batch complete count failed:\ndata:{}\ntaskid={}\nbatchid={}\nperiodnum={}\nbatchtask_cmdstatus={}"
                            .format(tb.inputdata.name, tb._taskid, tb._batchid,
                                    tb.periodnum, tb._cmdstatus.name))
                        return res
                    elif not task.isbatchcompletecountincreased:
                        task.batchcompletecount += 1
                        task.isbatchcompletecountincreased = True
                # 周期数+1
                # if task._is_period:
                #     tb.periodnum += 1
                #     task.periodnum += 1
                # PeriodNum=?,
                # Status=?,
                # Progress=?,
                # CmdRcvMsg=?,
                # Sequence=?,
                # UpdateTime=?
                if not self._dbmanager.update_iscoutbtask(
                        tb._platform,
                        tb._taskid,
                        tb._batchid,
                        updatefields={
                            'PeriodNum': tb.periodnum,
                            'Status': tb.cmdstatus.value,
                            'Progress': 1,
                            'Elapsed': tb.elapsed,
                            'CmdRcvMsg': tb.cmdrcvmsg,
                            'Sequence': tb._sequence,
                            'UpdateTime': tb.time,
                            'LastEndTime': helper_time.ts_since_1970_tz(),
                        }):
                    tb._cmdrcvmsg = "更新IScout子任务状态到本地数据库失败"
                    self._logger.error(
                        "Update IScoutBatchTask to db failed:\ndata:{}\ntaskid:{}\nbatchid:{}"
                        .format(tb.inputdata.name, tb._taskid, tb._batchid))
                    return res

            res = True
        except Exception:
            self._logger.error(
                "Deal first period task back error:\ntaskid:{}\nbatchid:{}\nclientid:{}\nerror:{}"
                .format(task.taskid, task.batchid, task._clientid,
                        traceback.format_exc()))
        return res