mirror of
https://github.com/KenanZhu/AutoLibrary.git
synced 2026-06-18 15:33:03 +08:00
refactor(ALTimerTaskManageWidget): 修复重复任务历史记录逻辑
- 修复 onRepeatTimerTaskIs 方法中日期循环索引错误,使用 %7 正确处理跨周星期计算 - 新增 OUTDATED 状态的专属处理逻辑,补全过期任务的历史记录 - 添加函数返回值并统一枚举比较方式为 ==,提高代码一致性
This commit is contained in:
@@ -575,17 +575,37 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget):
|
|||||||
timer_task: dict
|
timer_task: dict
|
||||||
) -> dict:
|
) -> dict:
|
||||||
|
|
||||||
|
# only these status are valid
|
||||||
|
valid_statuses = {ALTimerTaskStatus.EXECUTED, ALTimerTaskStatus.ERROR,
|
||||||
|
ALTimerTaskStatus.OUTDATED}
|
||||||
|
if status not in valid_statuses:
|
||||||
|
return timer_task
|
||||||
if "history" not in timer_task:
|
if "history" not in timer_task:
|
||||||
timer_task["history"] = []
|
timer_task["history"] = []
|
||||||
executed_time = datetime.now()
|
if status != ALTimerTaskStatus.OUTDATED:
|
||||||
duration = (executed_time - timer_task["execute_time"]).total_seconds()
|
executed_time = datetime.now()
|
||||||
timer_task["history"].append({
|
duration = (executed_time - timer_task["execute_time"]).total_seconds()
|
||||||
"execute_time": timer_task["execute_time"].strftime("%Y-%m-%d %H:%M:%S"),
|
timer_task["history"].append({
|
||||||
"executed_time": executed_time.strftime("%Y-%m-%d %H:%M:%S"),
|
"execute_time": timer_task["execute_time"].strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
"result": status,
|
"executed_time": executed_time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
"duration": duration if status is ALTimerTaskStatus.EXECUTED else 0,
|
"result": status,
|
||||||
"uuid": timer_task["task_uuid"]
|
"duration": duration,
|
||||||
})
|
"uuid": timer_task["task_uuid"]
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
current_time = datetime.now()
|
||||||
|
execute_time = timer_task["execute_time"]
|
||||||
|
execute_weekday = execute_time.weekday()
|
||||||
|
delta_days = (current_time - execute_time).days
|
||||||
|
for i in range(delta_days):
|
||||||
|
if (execute_weekday + i)%7 in timer_task["repeat_days"]:
|
||||||
|
timer_task["history"].append({
|
||||||
|
"execute_time": (execute_time + timedelta(days=i)).strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
|
"executed_time": (execute_time + timedelta(days=i)).strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
|
"result": status,
|
||||||
|
"duration": 0,
|
||||||
|
"uuid": timer_task["task_uuid"]
|
||||||
|
})
|
||||||
next_time = TimerUtils.calculateNextRepeatTime(
|
next_time = TimerUtils.calculateNextRepeatTime(
|
||||||
timer_task["repeat_days"],
|
timer_task["repeat_days"],
|
||||||
timer_task["repeat_hour"],
|
timer_task["repeat_hour"],
|
||||||
@@ -598,6 +618,7 @@ class ALTimerTaskManageWidget(QWidget, Ui_ALTimerTaskManageWidget):
|
|||||||
timer_task["executed"] = False
|
timer_task["executed"] = False
|
||||||
else:
|
else:
|
||||||
timer_task["status"] = status
|
timer_task["status"] = status
|
||||||
|
return timer_task
|
||||||
|
|
||||||
@Slot(dict)
|
@Slot(dict)
|
||||||
def onTimerTaskIsExecuted(
|
def onTimerTaskIsExecuted(
|
||||||
|
|||||||
Reference in New Issue
Block a user