python 定时任务管理封装

ba9020c2dabe42aaa508da75e09c2c07.png

主逻辑代码

# -*- coding: utf-8 -*-
# import apscheduler
import  pandas as pd
from datetime import datetime
# 导入调度器,此处使用BackgroundScheduler阻塞调度器
from apscheduler.schedulers.background import BackgroundScheduler
# 导入触发器,此处使用IntervalTrigger特定时间间隔触发
from apscheduler.triggers.interval import IntervalTrigger
from apscheduler.triggers.cron import CronTrigger
from apscheduler.triggers.date import DateTrigger
from apscheduler.executors.pool import ThreadPoolExecutor,ProcessPoolExecutor
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
from apscheduler.util import undefined
import os,time,sys,random,copy,json
from QhTestJob import Ui_Form
from PyQt5.QtWidgets import QApplication
from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt# cron定时调度(某一定时时刻执行)
# (int|str) 表示参数既可以是int类型,也可以是str类型
# (datetime | str) 表示参数既可以是datetime类型,也可以是str类型
# year (int|str) – 4-digit year -(表示四位数的年份,如2008年)
# month (int|str) – month (1-12) -(表示取值范围为1-12月)
# day (int|str) – day of the (1-31) -(表示取值范围为1-31日)
# week (int|str) – ISO week (1-53) -(格里历2006年12月31日可以写成2006年-W52-7(扩展形式)或2006W527(紧凑形式))
# day_of_week (int|str) – number or name of weekday (0-6 or mon,tue,wed,thu,fri,sat,sun) - (表示一周中的第几天,既可以用0-6表示也可以用其英语缩写表示)
# hour (int|str) – hour (0-23) - (表示取值范围为0-23时)
# minute (int|str) – minute (0-59) - (表示取值范围为0-59分)
# second (int|str) – second (0-59) - (表示取值范围为0-59秒)
# start_date (datetime|str) – earliest possible date/time to trigger on (inclusive) - (表示开始时间)
# end_date (datetime|str) – latest possible date/time to trigger on (inclusive) - (表示结束时间)
# timezone (datetime.tzinfo|str) – time zone to use for the date/time calculations (defaults to scheduler timezone) -(表示时区取值)#  interval 间隔调度(每隔多久执行)
# weeks (int) – number of weeks to wait
# days (int) – number of days to wait
# hours (int) – number of hours to wait
# minutes (int) – number of minutes to wait
# seconds (int) – number of seconds to wait
# start_date (datetime|str) – starting point for the interval calculation
# end_date (datetime|str) – latest possible date/time to trigger on
# timezone (datetime.tzinfo|str) – time zone to use for the date/time calculations# date 定时调度(作业只会执行一次)
# run_date (datetime|str) – the date/time to run the job at  -(任务开始的时间)
# timezone (datetime.tzinfo|str) – time zone for run_date if it doesn’t have one already
def QhRR(QhVALUE,QhVALUE1):print("{}--{}执行定时任务...".format(QhVALUE,QhVALUE1))class QhApscheduler():QhFiled = {"QhJabId": "None",            # 任务ID"QhJabName": "None",          # 任务名称"QhJabFuncName": "None",      # 任务名称 执行的程序名"QhTimesType": "None",        # 任务类型  重复 间隔 一次"QhYear": "None",             # 年"QhMonth": "None",            # 月"QhDay": "None",              # 日"QhWeek": "None",             # 周"QhDayOfWeek": "None",        # 星期几"QhHour": "None",             # 小时"QhMinute": "None",           # 分钟"QhSecond": "None",           # 秒钟"QhJabArgs": "None",          # 任务参数  函数参数"QhJabKwargs": "None",        # 任务参数  函数参数"QhJabStartDate": "None",     # 开始时间"QhJabNextRunTime": "None",   # 下次运行时间"QhJabLastRunTime": "None",    # 上次运行时间"QhJabStatus": "None"         # 任务状态 }def __init__(self, *args, **kwargs):self.QhCheduPath = os.path.dirname(os.path.abspath(__file__))         #绝对路径 用于获取定时模块的根目录print(self.QhCheduPath)self.QhCheduPoolJobDf = self._QhinitJobPoolCsv()QhExecutors = {'default':ThreadPoolExecutor(20),'processpool':ProcessPoolExecutor(10)}self.QhJobstores = {'default': SQLAlchemyJobStore(url='sqlite:///QhJobPoolDb/QhJabSqlite.sqlite')}self.Qhscheduler = BackgroundScheduler(jobstores=self.QhJobstores,executors=QhExecutors,misfire_grace_time=3,coalescing=True)self.Qhscheduler.start()self._QhInitAddJobFor()def _QhInitAddJobFor(self,QhIsFor = True):if self.QhCheduPoolJobDf.shape[0] == 0: returnfor QhInx,QhRow in self.QhCheduPoolJobDf.iterrows():QhJabId = QhRow["QhJabId"]QhJabName = QhRow["QhJabName"]QhJabFuncName = QhRow["QhJabFuncName"]QhTimesType = QhRow["QhTimesType"]QhYear = self.QhGeShiZH(QhRow["QhYear"])QhMonth = self.QhGeShiZH(QhRow["QhMonth"])QhDay = self.QhGeShiZH(QhRow["QhDay"])QhWeek = self.QhGeShiZH(QhRow["QhWeek"])QhDayOfWeek = self.QhGeShiZH(QhRow["QhDayOfWeek"])QhHour = self.QhGeShiZH(QhRow["QhHour"])QhMinute = self.QhGeShiZH(QhRow["QhMinute"])QhSecond = self.QhGeShiZH(QhRow["QhSecond"])QhJabArgs = self.QhGeShiZH(QhRow["QhJabArgs"])QhJabKwargs = self.QhGeShiZH(QhRow["QhJabKwargs"])       QhJabStartDate = QhRow["QhJabStartDate"]QhJabNextRunTime = QhRow["QhJabNextRunTime"]# QhJabLastRunTime = QhRow["QhJabLastRunTime"]# QhJabEndDate = QhRow["QhJabEndDate"]QhJabStatus = self.QhGeShiZH(QhRow["QhJabStatus"])print(QhYear,QhMonth,QhDay,QhWeek,QhDayOfWeek,QhHour,QhMinute,QhSecond)print(type(QhYear),type(QhMonth),type(QhDay),type(QhWeek),type(QhDayOfWeek),type(QhHour),type(QhMinute),type(QhSecond))self.QhAddJob(QhJabId,QhTimesType=QhTimesType,QhJabFuncName = QhJabFuncName,QhJabArgs=QhJabArgs,QhJabKwargs=QhJabKwargs,QhName = QhJabName,QhYear = QhYear,QhMonth = QhMonth,QhDay = QhDay,QhWeek = QhWeek,QhDayOfWeek = QhDayOfWeek,QhHour = QhHour,QhMinute = QhMinute,QhSecond = QhSecond,QhIsFor = QhIsFor,QhJabStatus=QhJabStatus)# QhIsFor当为True时,保存到csv文件,批量增加时的场景if QhIsFor == True:self.QhCheduPoolJobDf.to_csv(self.QhCheduPoolJobCsv, index=False,encoding='gbk')def _QhinitJobPoolCsv(self):# 初始化定时任务数据库文件夹# 作者:阙辉QhCheduPathpd = "{}\QhJobPoolDb".format(self.QhCheduPath)if os.path.exists(QhCheduPathpd):print("{} is exist!".format(QhCheduPathpd))else:os.mkdir(QhCheduPathpd)print("{} is not exist, create it!".format(QhCheduPathpd))self.QhCheduPoolJobCsv = "{}\QhJobPoolCsv.csv".format(QhCheduPathpd)if not os.path.exists(self.QhCheduPoolJobCsv):QhFiled = list(QhApscheduler.QhFiled.keys())self.QhCheduPoolJobDf = pd.DataFrame(columns=QhFiled)self.QhCheduPoolJobDf.to_csv(self.QhCheduPoolJobCsv, index=False)else:self.QhCheduPoolJobDf = pd.read_csv(self.QhCheduPoolJobCsv, encoding='gbk')self.QhCheduPoolJobDf.fillna("None", inplace=True)return self.QhCheduPoolJobDfdef QhAddJob(self, QhJabId,QhTimesType,    # 重复 间隔 一次QhJabFuncName,QhJabArgs=None,QhJabKwargs=None,QhName=None,QhYear = None,QhMonth = None,QhDay = None,QhWeek = None,QhDayOfWeek = None,QhHour = None,QhMinute = None,QhSecond = None,QhStartDate = None,QhEndDate = None,QhTimezone=None,QhJitter=None,misfire_grace_time=undefined,next_run_time=undefined,jobstore='default',executor='default',coalesce=undefined,max_instances=undefined,replace_existing=False,QhIsFor = False,QhJabStatus = None,QhJobIsOpen = False,):if self.Qhscheduler.get_job(QhJabId): print("{} is exist!".format(QhJabId))return   # 如果任务已经存在,则不添加if QhJabStatus == "已关闭" and (not QhJobIsOpen):print("{} 任务已关闭,不用新建!".format(QhJabId))returnQhTiggers = self.QhTiggers(QhTimesType =QhTimesType,QhYear = QhYear,QhMonth = QhMonth,QhDay = QhDay,QhWeek = QhWeek,QhDayOfWeek = QhDayOfWeek,QhHour = QhHour,QhMinute = QhMinute,QhSecond = QhSecond,QhStartDate = QhStartDate,QhEndDate = QhEndDate,QhTimezone=QhTimezone,QhJitter=QhJitter)if QhJabArgs!=None:QhJabArgs = tuple(QhJabArgs.split("+"))if QhJabKwargs != None:QhJabKwargs = QhJabKwargs.replace("+",',')QhJabKwargs = QhJabKwargs.replace("'",'"')QhJabKwargs = json.loads(QhJabKwargs)self.Qhscheduler.add_job(func=globals()[QhJabFuncName],trigger=QhTiggers,args=QhJabArgs,kwargs=QhJabKwargs,id=QhJabId,name=QhName,misfire_grace_time=misfire_grace_time,next_run_time=next_run_time,jobstore=jobstore,executor=executor,coalesce=coalesce,max_instances=max_instances,replace_existing=replace_existing,)# 函数参数还原输入格式处理  阙辉# print(QhJabArgs,type(QhJabArgs))if isinstance(QhJabArgs, tuple):QhJabArgs = str(QhJabArgs).replace("'",'').replace("(",'').\replace(")",'').replace(",","+").replace("+  ","+").replace("+ ","+")#     print(QhJabArgs,type(QhJabArgs))# print(QhJabKwargs,type(QhJabKwargs))if isinstance(QhJabKwargs, dict):QhJabKwargs = str(QhJabKwargs).replace("'",'"').replace(",","+")# print(QhJabKwargs,type(QhJabKwargs))QhAddJoblDic = copy.deepcopy(QhApscheduler.QhFiled) QhAddJoblDic["QhJabId"] = QhJabIdQhAddJoblDic["QhJabName"] = QhNameQhAddJoblDic["QhJabFuncName"] = "None" if QhJabFuncName==None else QhJabFuncNameQhAddJoblDic["QhTimesType"] = QhTimesTypeQhAddJoblDic["QhYear"] = "None" if QhYear==None else QhYearQhAddJoblDic["QhMonth"] = "None" if QhMonth==None else QhMonthQhAddJoblDic["QhDay"] = "None" if QhDay==None else QhDayQhAddJoblDic["QhWeek"] = "None" if QhWeek==None else QhWeekQhAddJoblDic["QhDayOfWeek"] = "None" if QhDayOfWeek==None else QhDayOfWeekQhAddJoblDic["QhHour"] = "None" if QhHour==None else QhHourQhAddJoblDic["QhMinute"] = "None" if QhMinute==None else QhMinuteQhAddJoblDic["QhSecond"] = "None" if QhSecond==None else QhSecondQhAddJoblDic["QhJabArgs"] = "None" if QhJabArgs==None else QhJabArgsQhAddJoblDic["QhJabKwargs"] = "None" if QhJabKwargs==None else QhJabKwargs# QhAddJoblDic["QhJabStartDate"] = "None"# QhAddJoblDic["QhJabNextRunTime"] = "None"# QhAddJoblDic["QhJabLastRunTime"] = "None"QhAddJoblDic["QhJabStatus"] = "已运行"try:   # 任务id存在,则更新任务,不存在则新增self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf["QhJabId"]==QhJabId].index[0]for QhKey,QhValue in QhAddJoblDic.items():if QhKey == "QhJabId":continue   self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf["QhJabId"]==QhJabId,QhKey] = QhValueexcept:QhCheduPoolJobDfRow = pd.DataFrame([QhAddJoblDic])print(QhCheduPoolJobDfRow)try:self.QhCheduPoolJobDf = self.QhCheduPoolJobDf._append(QhCheduPoolJobDfRow)except:self.QhCheduPoolJobDf = self.QhCheduPoolJobDf.append(QhCheduPoolJobDfRow)print(self.QhCheduPoolJobDf)# QhIsFor当为False时,保存到csv文件,单个增加时的场景if (not QhIsFor):self.QhCheduPoolJobDf.to_csv(self.QhCheduPoolJobCsv, index=False,encoding='gbk')def QhTiggers(self,QhTimesType,QhYear = None,QhMonth = None,QhDay = None,QhWeek = None,QhDayOfWeek = None,QhHour = None,QhMinute = None,QhSecond = None,QhStartDate = None,QhEndDate = None,QhTimezone=None,QhJitter=None):if QhTimesType == "重复":QhTiggers = CronTrigger(year=QhYear,month=QhMonth,day=QhDay,week=QhWeek,day_of_week=QhDayOfWeek,hour=QhHour,minute=QhMinute,second=QhSecond,start_date=QhStartDate,end_date=QhEndDate,timezone=QhTimezone,jitter=QhJitter)elif QhTimesType == "间隔":QhTiggers = IntervalTrigger(weeks= int(0) if QhWeek == None else QhWeek,days= 0 if QhDay == None else QhDay,hours= 0 if QhHour == None else QhHour,minutes= 0 if QhMinute == None else QhMinute,seconds= 0 if QhSecond == None else QhSecond,start_date=QhStartDate,end_date=QhEndDate,timezone=QhTimezone,jitter=QhJitter)elif QhTimesType == "一次":QhRunDate = datetime(0 if QhYear == None else QhYear, 0 if QhMonth == None else QhMonth, 0 if QhDay == None else QhDay, 0 if QhHour == None else QhHour, 0 if QhMinute == None else QhMinute, 0 if QhSecond == None else QhSecond)QhTiggers = DateTrigger(run_date=QhRunDate,timezone=QhTimezone)return QhTiggersdef QhPauseJob(self,QhJabId,QhIsFor=False):# 暂停任务 # QhIsFor当为False时,保存到csv文件,单个增加时的场景# 阙辉try:if QhJabId == "":print("任务ID不能空,请输入任务ID")returnif self.Qhscheduler.get_job(QhJabId):self.Qhscheduler.pause_job(QhJabId)print("暂停任务",QhJabId)self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabStatus'] = '已暂停'if (not QhIsFor):self.QhCheduPoolJobDf.to_csv(self.QhCheduPoolJobCsv, index=False, encoding='gbk')# AA = self.Qhscheduler.get_job(QhJabId)# print(AA.state)else:print("暂停失败,请检查任务ID,任务可能不存在")except:print("暂停失败,请检查任务ID,任务可能不存在")def QhPauseJobFor(self,QhIsFor=True):# 暂停所有任务for QhInx,QhRow in self.QhCheduPoolJobDf.iterrows():self.QhPauseJob(QhRow['QhJabId'],QhIsFor)def QhGetJobsState(self):for job in self.Qhscheduler.get_jobs():print(f"Job ID: {job.id}, 任务的下一次运行时间: {job.next_run_time}")print(f"Job ID: {job.id}, 任务是否有待执行: {job.pending}")# print(f"Job ID: {job.id}, 任务是否有待执行: {job.job_state}")# print(f"Job ID: {job.id}, 任务是否正在运行: {job.running}")def QhResumeJob(self,QhJabId,QhIsFor=False):# 恢复任务# QhIsFor当为False时,保存到csv文件,单个增加时的场景# 阙辉try:if QhJabId == "":print("任务ID不能空,请输入任务ID")returnif self.Qhscheduler.get_job(QhJabId):self.Qhscheduler.resume_job(QhJabId)print("恢复任务",QhJabId)self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabStatus'] = '已运行'if (not QhIsFor):self.QhCheduPoolJobDf.to_csv(self.QhCheduPoolJobCsv, index=False, encoding='gbk')else:print("恢复失败,请检查任务ID,任务可能不存在")except:print("恢复失败,请检查任务ID,任务可能不存在")def QhResumeJobFor(self,QhIsFor=True):# 恢复所有任务# QhIsFor当为False时,保存到csv文件,单个增加时的场景# 阙辉for QhInx,QhRow in self.QhCheduPoolJobDf.iterrows():self.QhResumeJob(QhRow['QhJabId'],QhIsFor)def QhRemoveJob(self,QhJabId,QhIsFor=False):# 删除任务# QhIsFor当为False时,保存到csv文件,单个增加时的场景# 阙辉try:if QhJabId == "":print("任务ID不能空,请输入任务ID")returnif self.Qhscheduler.get_job(QhJabId):self.Qhscheduler.remove_job(QhJabId)print("删除任务",QhJabId)self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabStatus'] = '已关闭'if (not QhIsFor):self.QhCheduPoolJobDf.to_csv(self.QhCheduPoolJobCsv, index=False, encoding='gbk')else:print("删除失败,请检查任务ID,任务可能不存在")except:print("删除失败,请检查任务ID,任务可能不存在")def QhRemoveJobFor(self,QhIsFor=True):# 删除所有任务# QhIsFor当为False时,保存到csv文件,单个增加时的场景# 阙辉for QhInx,QhRow in self.QhCheduPoolJobDf.iterrows():self.QhRemoveJob(QhRow['QhJabId'],QhIsFor)def QhReopenJob(self,QhJabId,QhIsFor=False):# 重新打开任务# QhIsFor当为False时,保存到csv文件,单个增加时的场景# 阙辉# try:if QhJabId == "":print("任务ID不能空,请输入任务ID")returnQhJabStatus = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabStatus'].values[0])if not self.Qhscheduler.get_job(QhJabId):if QhJabStatus == "已关闭":# QhJabId = QhRow["QhJabId"]QhJabName = self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabName'].values[0]QhJabFuncName = self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabFuncName'].values[0]QhTimesType = self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhTimesType'].values[0]QhYear = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhYear'].values[0])QhMonth = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhMonth'].values[0])QhDay = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhDay'].values[0])QhWeek = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhWeek'].values[0])QhDayOfWeek = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhDayOfWeek'].values[0])QhHour = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhHour'].values[0])QhMinute = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhMinute'].values[0])QhSecond = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhSecond'].values[0])QhJabArgs = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabArgs'].values[0])QhJabKwargs = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabKwargs'].values[0])       QhJabStartDate = self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabStartDate'].values[0]QhJabNextRunTime = self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabNextRunTime'].values[0]# QhJabLastRunTime = QhRow["QhJabLastRunTime"]# QhJabEndDate = QhRow["QhJabEndDate"]# QhJabStatus = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabStatus'].values[0])print(QhYear,QhMonth,QhDay,QhWeek,QhDayOfWeek,QhHour,QhMinute,QhSecond)print(type(QhYear),type(QhMonth),type(QhDay),type(QhWeek),type(QhDayOfWeek),type(QhHour),type(QhMinute),type(QhSecond))self.QhAddJob(QhJabId,QhTimesType=QhTimesType,QhJabFuncName = QhJabFuncName,QhJabArgs=QhJabArgs,QhJabKwargs=QhJabKwargs,QhName = QhJabName,QhYear = QhYear,QhMonth = QhMonth,QhDay = QhDay,QhWeek = QhWeek,QhDayOfWeek = QhDayOfWeek,QhHour = QhHour,QhMinute = QhMinute,QhSecond = QhSecond,QhJabStatus=QhJabStatus,QhIsFor = QhIsFor,QhJobIsOpen = True)  # 状态已在此函数更新# except:#     print("打开任务失败,请检查任务ID,任务可能不存在")def QhReopenJobFor(self,QhIsFor=True):# 重新打开所有任务# QhIsFor当为False时,保存到csv文件,单个增加时的场景# 阙辉for QhInx,QhRow in self.QhCheduPoolJobDf.iterrows():self.QhReopenJob(QhRow['QhJabId'],QhIsFor)def QhShouDongRunJob(self,QhJabId):# 手动运行任务# 阙辉try:if QhJabId == "":print("任务ID不能空,请输入任务ID")return# if self.Qhscheduler.get_job(QhJabId):QhJabFuncName = self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabFuncName'].values[0]QhJabArgs = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabArgs'].values[0])QhJabKwargs = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabKwargs'].values[0])QhJabFunc = globals().get(QhJabFuncName)if QhJabFunc:if QhJabArgs!= None:QhJabArgs = tuple(QhJabArgs.split("+"))QhJabFunc(*QhJabArgs)elif QhJabKwargs != None:QhJabKwargs = QhJabKwargs.replace("+",',')QhJabKwargs = QhJabKwargs.replace("'",'"')QhJabKwargs = json.loads(QhJabKwargs)QhJabFunc(**QhJabKwargs)else:print(f"Function '{QhJabFuncName}' not found.")# self.Qhscheduler.run_job(QhJabId)print("手动执行任务",QhJabId)except Exception as e:print(f"An error occurred while executing the job: {e}")print("2手动执行任务失败,请检查任务ID,任务可能不存在")def QhShouDongRunJobFor(self):# 手动运行所有任务# 阙辉for QhInx,QhRow in self.QhCheduPoolJobDf.iterrows():self.QhShouDongRunJob(QhRow['QhJabId'])def QhXiuGaiJob(self,QhJabId,QhIsFor=True):# 修改任务方案:先删除,修改后重新添加pass# self.QhCheduPoolJobDf = self._QhinitJobPoolCsv()  # 重新加载任务池数据# QhJabName = self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabName'].values[0]# QhJabFuncName = self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabFuncName'].values[0]# QhTimesType = self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhTimesType'].values[0]# QhYear = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhYear'].values[0])# QhMonth = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhMonth'].values[0])# QhDay = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhDay'].values[0])# QhWeek = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhWeek'].values[0])# QhDayOfWeek = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhDayOfWeek'].values[0])# QhHour = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhHour'].values[0])# QhMinute = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhMinute'].values[0])# QhSecond = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhSecond'].values[0])# QhJabArgs = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabArgs'].values[0])# QhJabKwargs = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabKwargs'].values[0])       # QhJabStartDate = self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabStartDate'].values[0]# QhJabNextRunTime = self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabNextRunTime'].values[0]# # QhJabLastRunTime = QhRow["QhJabLastRunTime"]# # QhJabEndDate = QhRow["QhJabEndDate"]# # QhJabStatus = self.QhGeShiZH(self.QhCheduPoolJobDf.loc[self.QhCheduPoolJobDf['QhJabId'] == QhJabId, 'QhJabStatus'].values[0])# print(QhYear,QhMonth,QhDay,QhWeek,QhDayOfWeek,QhHour,QhMinute,QhSecond)# print(type(QhYear),type(QhMonth),type(QhDay),type(QhWeek),type(QhDayOfWeek),type(QhHour),type(QhMinute),type(QhSecond))# self.Qhscheduler.modify_job()def QhGeShiZH(self,QhValue):# 时间格式转化  后期需要优化# 作者:阙辉try:if isinstance(QhValue, str):if QhValue in ["None","","0"]:# print("zhuan01")return Noneelse:try:# print("zhuan02")return int(QhValue)except:# print("zhuan03")return QhValueelse:# print("zhuan04")return int(QhValue)except:# print("zhuan05")return Noneclass QhTestApschedulerGui(QtWidgets.QWidget,Ui_Form):def __init__(self, parent=None):super(QhTestApschedulerGui, self).__init__(parent)self.setupUi(self)self.aa=QhApscheduler()self.pushButton_2.clicked.connect(self.QhPauseJob)self.pushButton_18.clicked.connect(self.QhResumeJob)self.pushButton_19.clicked.connect(self.aa.QhGetJobsState)self.pushButton.clicked.connect(self.QhAddJob)self.pushButton_3.clicked.connect(self.QhRemoveJob)self.pushButton_20.clicked.connect(self.aa.QhPauseJobFor)self.pushButton_21.clicked.connect(self.aa.QhResumeJobFor)self.pushButton_22.clicked.connect(self.aa.QhRemoveJobFor)self.pushButton_23.clicked.connect(self.aa.QhReopenJobFor)self.pushButton_6.clicked.connect(self.QhReopenJob)self.pushButton_4.clicked.connect(self.QhShouDongRunJob)self.pushButton_24.clicked.connect(self.aa.QhShouDongRunJobFor)def QhAddJob(self):QhJobId = self.lineEdit_5.text()if QhJobId == "":print("任务ID不能空,请输入任务ID")returnQhJobName = "{}-Name".format(QhJobId)QhScoends = random.randint(8, 20)QhTimesType = "间隔"QhJabFuncName = "QhRR"self.aa.QhAddJob(QhJobId,QhTimesType=QhTimesType,QhJabFuncName = QhJabFuncName,QhName = QhJobName,QhSecond = QhScoends,QhJabArgs = "{QhJobId}-测试顺序+QUEHUI".format(QhJobId=QhJobId),)print("添加任务{}".format(QhJobId))def QhPauseJob(self):QhJobId = self.lineEdit.text()print(QhJobId)self.aa.QhPauseJob(QhJobId)def QhResumeJob(self):QhJobId = self.lineEdit_18.text()print(QhJobId)self.aa.QhResumeJob(QhJobId)def QhRemoveJob(self):QhJobId = self.lineEdit_2.text()print(QhJobId)self.aa.QhRemoveJob(QhJobId)def QhReopenJob(self):QhJobId = self.lineEdit_6.text()print(QhJobId)self.aa.QhReopenJob(QhJobId)def QhShouDongRunJob(self):QhJobId = self.lineEdit_3.text()print(QhJobId)self.aa.QhShouDongRunJob(QhJobId)if __name__ == '__main__':# aa=QhApscheduler()# aa._QhInitAddJobFor() # # 保持主线程运行# try:#     while True:#         time.sleep(2)# except (KeyboardInterrupt, SystemExit):#     aa.Qhscheduler.shutdown()QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)qh_app = QApplication(sys.argv)                 # 创建应用实例qh_MyWindows = QhTestApschedulerGui()                        # 创建窗口实例qh_MyWindows.show()                             # 显示窗口qh_n = qh_app.exec()              # 执行exec()方法,进入事件循环,如果遇到窗口退出命令,返回整数qh_nprint(qh_n)                       # 输出输出关闭事件返回的整数try:                              # 捕获程序退出事件sys.exit(qh_n)                    # 通知python系统,结束程序运行except SystemExit:print("请在此做一些其他工作。")       # python解释器停止执行前的工作

UI代码

# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'QhTestJob.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.from PyQt5 import QtCore, QtGui, QtWidgetsclass Ui_Form(object):def setupUi(self, Form):Form.setObjectName("Form")Form.resize(632, 610)self.gridLayout = QtWidgets.QGridLayout(Form)self.gridLayout.setObjectName("gridLayout")self.verticalLayout = QtWidgets.QVBoxLayout()self.verticalLayout.setObjectName("verticalLayout")self.horizontalLayout_5 = QtWidgets.QHBoxLayout()self.horizontalLayout_5.setObjectName("horizontalLayout_5")self.pushButton = QtWidgets.QPushButton(Form)self.pushButton.setObjectName("pushButton")self.horizontalLayout_5.addWidget(self.pushButton)self.lineEdit_5 = QtWidgets.QLineEdit(Form)self.lineEdit_5.setMinimumSize(QtCore.QSize(500, 28))self.lineEdit_5.setMaximumSize(QtCore.QSize(500, 16777215))self.lineEdit_5.setObjectName("lineEdit_5")self.horizontalLayout_5.addWidget(self.lineEdit_5)self.verticalLayout.addLayout(self.horizontalLayout_5)self.horizontalLayout_4 = QtWidgets.QHBoxLayout()self.horizontalLayout_4.setObjectName("horizontalLayout_4")self.pushButton_2 = QtWidgets.QPushButton(Form)self.pushButton_2.setObjectName("pushButton_2")self.horizontalLayout_4.addWidget(self.pushButton_2)self.lineEdit = QtWidgets.QLineEdit(Form)self.lineEdit.setMinimumSize(QtCore.QSize(230, 28))self.lineEdit.setMaximumSize(QtCore.QSize(500, 16777215))self.lineEdit.setObjectName("lineEdit")self.horizontalLayout_4.addWidget(self.lineEdit)self.verticalLayout.addLayout(self.horizontalLayout_4)self.horizontalLayout_18 = QtWidgets.QHBoxLayout()self.horizontalLayout_18.setObjectName("horizontalLayout_18")self.pushButton_18 = QtWidgets.QPushButton(Form)self.pushButton_18.setObjectName("pushButton_18")self.horizontalLayout_18.addWidget(self.pushButton_18)self.lineEdit_18 = QtWidgets.QLineEdit(Form)self.lineEdit_18.setMinimumSize(QtCore.QSize(230, 28))self.lineEdit_18.setMaximumSize(QtCore.QSize(500, 16777215))self.lineEdit_18.setObjectName("lineEdit_18")self.horizontalLayout_18.addWidget(self.lineEdit_18)self.verticalLayout.addLayout(self.horizontalLayout_18)self.horizontalLayout_3 = QtWidgets.QHBoxLayout()self.horizontalLayout_3.setObjectName("horizontalLayout_3")self.pushButton_3 = QtWidgets.QPushButton(Form)self.pushButton_3.setObjectName("pushButton_3")self.horizontalLayout_3.addWidget(self.pushButton_3)self.lineEdit_2 = QtWidgets.QLineEdit(Form)self.lineEdit_2.setMinimumSize(QtCore.QSize(230, 28))self.lineEdit_2.setMaximumSize(QtCore.QSize(500, 16777215))self.lineEdit_2.setObjectName("lineEdit_2")self.horizontalLayout_3.addWidget(self.lineEdit_2)self.verticalLayout.addLayout(self.horizontalLayout_3)self.horizontalLayout_6 = QtWidgets.QHBoxLayout()self.horizontalLayout_6.setObjectName("horizontalLayout_6")self.pushButton_6 = QtWidgets.QPushButton(Form)self.pushButton_6.setObjectName("pushButton_6")self.horizontalLayout_6.addWidget(self.pushButton_6)self.lineEdit_6 = QtWidgets.QLineEdit(Form)self.lineEdit_6.setMinimumSize(QtCore.QSize(230, 28))self.lineEdit_6.setMaximumSize(QtCore.QSize(500, 16777215))self.lineEdit_6.setObjectName("lineEdit_6")self.horizontalLayout_6.addWidget(self.lineEdit_6)self.verticalLayout.addLayout(self.horizontalLayout_6)self.horizontalLayout_2 = QtWidgets.QHBoxLayout()self.horizontalLayout_2.setObjectName("horizontalLayout_2")self.pushButton_4 = QtWidgets.QPushButton(Form)self.pushButton_4.setObjectName("pushButton_4")self.horizontalLayout_2.addWidget(self.pushButton_4)self.lineEdit_3 = QtWidgets.QLineEdit(Form)self.lineEdit_3.setMinimumSize(QtCore.QSize(230, 28))self.lineEdit_3.setMaximumSize(QtCore.QSize(500, 16777215))self.lineEdit_3.setObjectName("lineEdit_3")self.horizontalLayout_2.addWidget(self.lineEdit_3)self.verticalLayout.addLayout(self.horizontalLayout_2)self.horizontalLayout = QtWidgets.QHBoxLayout()self.horizontalLayout.setObjectName("horizontalLayout")self.pushButton_5 = QtWidgets.QPushButton(Form)self.pushButton_5.setObjectName("pushButton_5")self.horizontalLayout.addWidget(self.pushButton_5)self.lineEdit_4 = QtWidgets.QLineEdit(Form)self.lineEdit_4.setMinimumSize(QtCore.QSize(230, 28))self.lineEdit_4.setMaximumSize(QtCore.QSize(500, 16777215))self.lineEdit_4.setObjectName("lineEdit_4")self.horizontalLayout.addWidget(self.lineEdit_4)self.verticalLayout.addLayout(self.horizontalLayout)self.pushButton_19 = QtWidgets.QPushButton(Form)self.pushButton_19.setObjectName("pushButton_19")self.verticalLayout.addWidget(self.pushButton_19)self.pushButton_24 = QtWidgets.QPushButton(Form)self.pushButton_24.setObjectName("pushButton_24")self.verticalLayout.addWidget(self.pushButton_24)self.pushButton_20 = QtWidgets.QPushButton(Form)self.pushButton_20.setObjectName("pushButton_20")self.verticalLayout.addWidget(self.pushButton_20)self.pushButton_21 = QtWidgets.QPushButton(Form)self.pushButton_21.setObjectName("pushButton_21")self.verticalLayout.addWidget(self.pushButton_21)self.pushButton_22 = QtWidgets.QPushButton(Form)self.pushButton_22.setObjectName("pushButton_22")self.verticalLayout.addWidget(self.pushButton_22)self.pushButton_23 = QtWidgets.QPushButton(Form)self.pushButton_23.setObjectName("pushButton_23")self.verticalLayout.addWidget(self.pushButton_23)self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)self.retranslateUi(Form)QtCore.QMetaObject.connectSlotsByName(Form)def retranslateUi(self, Form):_translate = QtCore.QCoreApplication.translateForm.setWindowTitle(_translate("Form", "Form"))self.pushButton.setText(_translate("Form", "添加任务"))self.pushButton_2.setText(_translate("Form", "暂停任务"))self.pushButton_18.setText(_translate("Form", "启动任务"))self.pushButton_3.setText(_translate("Form", "删除任务"))self.pushButton_6.setText(_translate("Form", "打开任务"))self.pushButton_4.setText(_translate("Form", "手动执行"))self.pushButton_5.setText(_translate("Form", "获取任务状态"))self.pushButton_19.setText(_translate("Form", "获取所有任务的状态"))self.pushButton_24.setText(_translate("Form", "手动执行所有任务"))self.pushButton_20.setText(_translate("Form", "暂停所有任务"))self.pushButton_21.setText(_translate("Form", "恢复所有任务"))self.pushButton_22.setText(_translate("Form", "关闭所有任务"))self.pushButton_23.setText(_translate("Form", "打开所有任务"))

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/64913.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

APP投放的归因框架设计

一、归因相关概念回顾 在广告归因简介中我们介绍常见的归因模型和归因方法,我们先来回顾一下: 1. 背景 2. 设备标识 3. 归因模型 归因模型的多样性意味着每种模型都有其独特的优势和局限。关键在于选择一个与您的业务场景相匹配的模型,并且…

Kunlun 2280服务器(ARM)Raid卡磁盘盘符漂移问题解决

一、问题描述 1、服务器:Kunlun 2280服务器 ARM 2、操作系统:Euler2.0Sp10 Arm 3、Raid卡型号:MeGaRAID 9560-8i 4、Raid配置:2块配置Raid1作为系统盘,剩余磁盘配置Raid5 作为数据盘 二、问题现象 1、使用IBMC页面配置Raid卡,1个Raid1 系统盘和1个Raid5数…

[搜广推]王树森推荐系统——Deep Retrieval 召回

Deep Retrieval 简介 Deep Retrieval 是一种推荐系统框架,它将物品表示为路径(path),并在线上查找与用户最匹配的路径。 这种方法与传统的双塔模型不同,后者通常将用户和物品表示为向量,并在线上进行最近邻…

RabbitMQ 的7种工作模式

RabbitMQ 共提供了7种⼯作模式,进⾏消息传递,. 官⽅⽂档:RabbitMQ Tutorials | RabbitMQ 1.Simple(简单模式) P:⽣产者,也就是要发送消息的程序 C:消费者,消息的接收者 Queue:消息队列,图中⻩⾊背景部分.类似⼀个邮箱,可以缓存消息;⽣产者向其中投递消息,消费者从其中取出消息…

PCIe_Host驱动分析_设备枚举

往期内容 本文章相关专栏往期内容,PCI/PCIe子系统专栏: 嵌入式系统的内存访问和总线通信机制解析、PCI/PCIe引入 深入解析非桥PCI设备的访问和配置方法 PCI桥设备的访问方法、软件角度讲解PCIe设备的硬件结构 深入解析PCIe设备事务层与配置过程 PCIe的三…

深入浅出:多功能 Copilot 智能助手如何借助 LLM 实现精准意图识别

阅读原文 1. Copilot中的意图识别 如果要搭建一个 Copilot 智能助手,比如支持 知识问答、数据分析、智能托管、AIGC 等众多场景或能力,那么最核心的就是基于LLM进行意图识别分发能力,意图识别的准确率直接决定了 Copilot 智能助手的能力上限…

Jo-im开发:用于WebRTC的ICE中继服务器Coturn搭建

前言 本人计划开发一套具备文本、语音、视频通话功能的IM demo,同时具备多人在线会议功能,按习惯大概会开源版定义名称为Duihao jo-im,本案主要用于实现语音视频通话的基础组件支撑。因为我们选择基于WebRTC实现IM中语音、视频通话&#xff…

【CVE-2024-53375】TP-Link Archer系列路由器认证操作系统命令注入(内附远离和代码利用)

CVE-2024-53375 TP-Link Archer系列路由器认证操作系统命令注入 受影响的设备 使用 HomeShield 功能的 TP-Link 设备容易受到此漏洞的影响。这包括 TP-Link Archer 系列的多款路由器。 经过测试 Archer AXE75(EU)_V1_1.2.2 Build 20240827(发布日期 2024 年 11 月 4 日)…

程控电阻箱应用中需要注意哪些安全事项?

程控电阻箱是一种用于精确控制电路中电流和电压的电子元件,广泛应用于电子实验、测试设备以及精密测量仪器中。在应用程控电阻箱时,为确保安全和设备的正常运行,需要注意以下几个安全事项: 1. 正确连接:确保电阻箱与电…

Promise链式调用

Promise链式调用 上一篇我们实现了通过promise的方式实现获取国家基本信息,本次我们来使用promise链式调用来实现邻国的展现 首先,我们从第一个国家中获取到邻国的国家代码名称 const neighbour data[0].borders[0];然后我们通过fetch来获取邻国信息&a…

Elasticsearch相关知识@1

目录标题 Lucene1. **什么是 Lucene?**2. **Lucene 在 Elasticsearch 中的作用**3. **Lucene 的核心功能**(1) **倒排索引**(2) **分词**(3) **查询解析**(4) **相关性评分** 4. **为什么 Elasticsearch 使用 Lucene?**5. **Lucene 和 Elasticsearch 的区别**6. **总结** 分片…

UE5 渲染管线 学习笔记

兰伯特 SSS为散射的意思 带Bias的可以根据距离自动切换mip的卷积值 而带Level的值mipmaps的定值 #define A8_SAMPLE_MASK .a 这样应该就很好理解了 这个只采样a通道 带Level的参考上面的 朝左上和右下进行模糊 带Bias参考上面

canvas绘制仪表盘刻度盘

canvas画布可以实现在网页上绘制图形的方法,比如图表、图片处理、动画、游戏等。今天我们在vue模板下用canvas实现仪表盘的绘制。 对canvas不熟悉的同学可以先了解下canvas的API文档:canvas API中文网 - Canvas API中文文档首页地图 一、创建模板&#…

Spring Boot 中实现自定义注解记录接口日志功能

👨🏻‍💻 热爱摄影的程序员 👨🏻‍🎨 喜欢编码的设计师 🧕🏻 擅长设计的剪辑师 🧑🏻‍🏫 一位高冷无情的全栈工程师 欢迎分享 / 收藏 / 赞 / 在看…

【超详细实操内容】django的身份验证系统之限制用户访问的三种方式

目录 1、使用request.user.is_authenticated属性 2、装饰器login_required 3、LoginRequiredMixin类 通常情况下,网站都会对用户限制访问,例如,未登录的用户不可访问用户中心页面。Django框架中使用request.user.isauthenticated属性、装饰器loginrequired和LoginRequire…

scss配置全局变量报错[sass] Can‘t find stylesheet to import.

路径没有错误,使用别名即可 后又提示Deprecation Warning: Sass import rules are deprecated and will be removed in Dart Sass 3.0.0. 将import改为use 使用时在$前添加全局变量所在文件,即variable.

基于Qlearning强化学习的机器人路线规划matlab仿真

目录 1.算法仿真效果 2.算法涉及理论知识概要 3.MATLAB核心程序 4.完整算法代码文件获得 1.算法仿真效果 matlab2022a仿真结果如下(完整代码运行后无水印): 训练过程 测试结果 仿真操作步骤可参考程序配套的操作视频。 2.算法涉及理论…

9 RCC使用HSE、HSI配置时钟

一、时钟树 RCC:reset clock control,复位和时钟控制器。HSE是外部的高速时钟信号,可以由有源晶振或者无源晶振提供。如果使用HSE或者HSE经过PLL倍频之后的时钟作为系统时钟SYSCLK,当HSE故障时候,不仅HSE会被关闭,PLL…

认识数据结构之——排序

一、 插入排序: 直接插入排序(以排升序为例): 排序思想: 单趟:记录某个位置的值,一个一个和前面的值比较,碰到更大的就往后覆盖,碰到更小的或者相等的就结束,最后将记录的值插入到…

uniapp 微信小程序 功能入口

单行单独展示 效果图 html <view class"shopchoose flex jsb ac" click"routerTo(要跳转的页面)"><view class"flex ac"><image src"/static/dyd.png" mode"aspectFit" class"shopchooseimg"&g…