解决bug
This commit is contained in:
@@ -296,12 +296,26 @@ class MessagePushTask(MessagePluginInterface):
|
||||
# 解析执行时间
|
||||
if recurring_time:
|
||||
try:
|
||||
hour, minute = map(int, recurring_time.split(':'))
|
||||
except (ValueError, AttributeError):
|
||||
self.LOG.error(f"无效的执行时间格式: {recurring_time}")
|
||||
# 处理 timedelta 对象
|
||||
if isinstance(recurring_time, timedelta):
|
||||
total_seconds = int(recurring_time.total_seconds())
|
||||
hour = total_seconds // 3600
|
||||
minute = (total_seconds % 3600) // 60
|
||||
second = total_seconds % 60
|
||||
else:
|
||||
# 处理字符串格式
|
||||
time_parts = str(recurring_time).split(':')
|
||||
if len(time_parts) == 3:
|
||||
hour, minute, second = map(int, time_parts)
|
||||
else:
|
||||
hour, minute = map(int, time_parts)
|
||||
second = 0
|
||||
except (ValueError, AttributeError) as e:
|
||||
self.LOG.error(f"无效的执行时间格式: {recurring_time}, 错误: {e}")
|
||||
return None
|
||||
else:
|
||||
hour, minute = schedule_time.hour, schedule_time.minute
|
||||
second = 0
|
||||
|
||||
# 获取当前时间
|
||||
now = datetime.now()
|
||||
@@ -313,7 +327,7 @@ class MessagePushTask(MessagePluginInterface):
|
||||
# 根据重复间隔计算下次执行时间
|
||||
if recurring_interval == 'daily':
|
||||
# 每天执行
|
||||
next_time = now.replace(hour=hour, minute=minute, second=0, microsecond=0)
|
||||
next_time = now.replace(hour=hour, minute=minute, second=second, microsecond=0)
|
||||
if next_time <= now:
|
||||
next_time = next_time + timedelta(days=1)
|
||||
|
||||
@@ -343,7 +357,7 @@ class MessagePushTask(MessagePluginInterface):
|
||||
else:
|
||||
days_ahead = next_weekday - current_weekday
|
||||
|
||||
next_time = now.replace(hour=hour, minute=minute, second=0, microsecond=0) + timedelta(days=days_ahead)
|
||||
next_time = now.replace(hour=hour, minute=minute, second=second, microsecond=0) + timedelta(days=days_ahead)
|
||||
|
||||
except (json.JSONDecodeError, ValueError, IndexError) as e:
|
||||
self.LOG.error(f"处理每周执行日失败: {e}")
|
||||
@@ -374,14 +388,14 @@ class MessagePushTask(MessagePluginInterface):
|
||||
|
||||
# 处理无效日期(如2月30日)
|
||||
try:
|
||||
next_time = datetime(next_year, next_month, monthly_day, hour, minute)
|
||||
next_time = datetime(next_year, next_month, monthly_day, hour, minute, second)
|
||||
except ValueError:
|
||||
# 如果日期无效,使用该月的最后一天
|
||||
if next_month == 12:
|
||||
last_day = 31
|
||||
else:
|
||||
last_day = (datetime(next_year, next_month + 1, 1) - timedelta(days=1)).day
|
||||
next_time = datetime(next_year, next_month, last_day, hour, minute)
|
||||
next_time = datetime(next_year, next_month, last_day, hour, minute, second)
|
||||
|
||||
except Exception as e:
|
||||
self.LOG.error(f"处理每月执行日失败: {e}")
|
||||
|
||||
Reference in New Issue
Block a user