示例#1
0
        task_run_status = 3

        time.sleep(0.5)
        traceback.print_exc()
        time.sleep(0.5)

        if 'MSG_INFO' in dir():
            log.PrintErrorLog("{0}:{1}:{2}".format(MSG_INFO["MSG_NO"], MSG_INFO["MSG_STR"],e))
        else:
            log.PrintErrorLog(e)

    finally:

        if 'logFile' in dir():
            logFile.close()

            # 把日志写入数据库中
            with open(logFilePath, encoding='UTF-8') as f:
                logContext = f.read()

            logContext = logContext.replace("'","''")

            strSql = "INSERT INTO `YwzcWebSys`.`insbusi_inserneworginfolog` (`oper_sys`, `insert_datetime`, `log_txt`, `org_code_id`, `task_status`) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}')".format(
                init["task_name"],
                datetime.datetime.now(),
                logContext,
                init["id"],
                task_run_status,
            )
            mySqlConn.execute(strSql)
示例#2
0
# 创建到账户库的链接
TNS_NAME = '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=%s)(PORT=%s)))(CONNECT_DATA=(SERVICE_NAME=%s)))' % (
    CParam["ORACLE_HOST"], CParam["ORACLE_PORT"],
    CParam["ORACLE_SERVICE_NAME"])
oraConn = cxOracle(CParam["ORACLE_USER_NAME"], CParam["ORACLE_USER_PASSWD"],
                   TNS_NAME)

oraStrSql = "SELECT * FROM {0} A".format(CParam["TABLE_NAME"])

rtnDatas = oraConn.QueryDict(oraStrSql)

for x in rtnDatas:

    myStrSql = "select count(*) as cnt from `YwzcWebSys`.`commset_calendar` where `bookset` = '{0}' and  `physical_date` = {1}".format(
        x["BOOKSET"], x["PHYSICAL_DATE"])
    dx = mySqlConn.query(myStrSql)[0]

    if str(dx["cnt"]) == "0":

        myStrSql = "INSERT INTO `YwzcWebSys`.`commset_calendar` (`bookset`, `physical_date`, `date_flag`, `date_status`) VALUES ('{0}', '{1}', '{2}', '{3}');".format(
            x["BOOKSET"],
            x["PHYSICAL_DATE"],
            x["DATE_FLAG"],
            x["DATE_STATUS"],
        )

        mySqlConn.execute(myStrSql)

    else:
        print("skip")
示例#3
0
def RunMainPoint(x, mySqlConn):

    RedisR = RedisQueue("req", x['id'], "192.168.169.30", 6379, 1)

    # 执行前先清空队列
    RedisR.delete_db()

    # time.sleep(20)

    # 组装新的SAMBA网络共享目录 目的IP 目的本地路径 拷贝服务通过网络映射方式进行
    x["unc_access_base_path"] = "\\\\%s\\%s" % (
        x["host_ip"], x["file_save_path"].replace(":\\", "$\\"))
    # 目录文件汇总,防止文件总数为0的情况下造成程序异常
    x["file_cnt"] = "0"

    # 定义一个进程运行状态字典子项 用于进程状态的记录
    x["run_status"] = "3"

    Print_Dict_KandV(x, "Init")
    time.sleep(1)

    # 引入本程序核心类
    chfc = CopyHostFileClass(x, mySqlConn, RedisR)

    # 测试各路径是否能正常访问
    try:
        archNasPath = x["arch_nas_path"]
        archNasPathUser = x["arch_nas_user"]
        archNasPathUserPasswd = x['arch_nas_passwd']
        rtnResult = Net_RemtePath_IsAccess(archNasPath, archNasPathUser,
                                           archNasPathUserPasswd)
        if rtnResult != True:
            x["run_status"] = "3"
            x["run_msg"] = "10001:NAS 服务器访问错误,请检查!"
            raise Exception(rtnResult)

        fileUncPath = x["unc_access_base_path"]
        fileUncUser = x["host_user"]
        fileUncUserPasswd = x["host_user_passwd"]
        rtnResult = Net_RemtePath_IsAccess(fileUncPath, fileUncUser,
                                           fileUncUserPasswd)
        if rtnResult != True:
            x["run_status"] = "3"
            x["run_msg"] = "1002:文件目标服务器UNC访问错误,请检查!"
            raise Exception(rtnResult)

        # 如果根目录文件为空,则直接报错
        rtnCnt = Count_File_Num(x['unc_access_base_path'])
        if rtnCnt == 0:
            x["run_status"] = "3"
            x["run_msg"] = "1003:指定转换目标服务器根目录文件为0,跳过本次任务!"
            raise Exception(rtnResult)

        # 开始处理业务逻辑
        excludList = chfc.Get_ExcludeList()
        moveCnt = chfc.Move_File_Proc(excludList)

        # 删除空目录
        while True:
            # 判断队列中是否还有记录 如果为空则认为处理完毕,开始删除空目录
            moveRemCnt = RedisR.qsize()
            # print(moveRemCnt)
            if moveRemCnt == 0:
                break

        # 删除空目录
        chfc.Delete_Empty(x["unc_access_base_path"], excludList)

    except Exception as e:
        ''' 写一条错误日志 '''
        strSql = '''
            INSERT INTO `backtaskmget_filebacktasklog` (
                `task_name`,
                `task_status`,
                `task_run_date`,
                `task_run_time`,
                `host_ip`,
                `file_modify_dt`,
                `md5_string`,
                `file_name`,
                `file_save_path`,
                `arch_nas_path`,
                `file_siz`,
                `remark`
            )
            VALUES
                (
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s'
                );
        ''' % (
            x["task_name"],
            "3",
            datetime.datetime.now().strftime('%Y-%m-%d'),
            datetime.datetime.now().strftime('%H:%M:%S'),
            x["host_ip"],
            datetime.datetime.now().strftime('1900-01-01 00:00:00.000000'),
            "",
            "",
            "",
            x["arch_nas_path"],
            0,
            json.dumps(x, cls=DateEncoder, ensure_ascii=False),
        )
        mySqlConn.execute(strSql)
        print(C_PrintLog.errinfo(), x["task_name"], x["run_status"], e)
示例#4
0
def __Client_Sub_Move_Main(redisReqKeyName):

    hostList = []

    while True:

        RedisR = RedisQueue("req", redisReqKeyName, "192.168.169.30", 6379, 1)

        if RedisR.qsize() == 0:
            break

        copyParams = RedisR.get_wait()[1]  # 返回为元祖,原始入参字典在第二个顺位
        # copyParams = RedisR.get_nowait()  # 返回为字典

        strSql = ""

        if copyParams:

            # 缺一段逻辑,用于增加对hostip只判断一次是否可以访问的函数
            pass

            # 对入参进行解码
            x = eval(copyParams.decode("utf-8"))

            archNasPath = x["arch_nas_path"]
            archNasPathUser = x["arch_nas_user"]
            archNasPathUserPasswd = x['arch_nas_passwd']
            rtnResult = Net_RemtePath_IsAccess(archNasPath, archNasPathUser,
                                               archNasPathUserPasswd)
            if rtnResult != True:
                x["run_status"] = "3"
                x["run_msg"] = "10001:NAS 服务器访问错误,请检查!"
                raise Exception(rtnResult)

            fileUncPath = x["unc_access_base_path"]
            fileUncUser = x["host_user"]
            fileUncUserPasswd = x["host_user_passwd"]
            rtnResult = Net_RemtePath_IsAccess(fileUncPath, fileUncUser,
                                               fileUncUserPasswd)
            if rtnResult != True:
                x["run_status"] = "3"
                x["run_msg"] = "1002:文件目标服务器UNC访问错误,请检查!"
                raise Exception(rtnResult)

            # 引入核心参数
            chfc = CopyHostFileClass(x, RedisR, mySqlConn)

            # 运行文件拷贝编码进程
            chfc.Copy_File2Nas_Main()

            strSql = """
                INSERT INTO `backtaskmget_filebacktasklog` (
                    `task_name`,
                    `task_status`,
                    `task_run_date`,
                    `task_run_time`,
                    `host_ip`,
                    `file_modify_dt`,
                    `md5_string`,
                    `file_name`,
                    `file_save_path`,
                    `arch_nas_path`,
                    `file_siz`,
                    `remark`
                )
                VALUES
                    (
                        '%s',
                        '%s',
                        '%s',
                        '%s',
                        '%s',
                        '%s',
                        '%s',
                        '%s',
                        '%s',
                        '%s',
                        '%s',
                        '%s'
                    );
            """ % (
                x["task_name"],
                x["run_status"],
                datetime.datetime.now().strftime('%Y-%m-%d'),
                datetime.datetime.now().strftime('%H:%M:%S'),
                x["host_ip"],
                x["file_mod_time"],
                x["file_md5_code"],
                x["c_local_file_name"],
                x["c_local_file_dir"],
                x["nas_new_file_path"],
                x["file_size"],
                json.dumps(x, cls=DateEncoder, ensure_ascii=False),
            )
            # print(C_PrintLog.debug(), Comp_MultilineText(strSql.replace("\\", "\\\\")))
            mySqlConn.execute(strSql.replace("\\", "\\\\"))