活动每日sp如果已经打完则延时#146
Conversation
审阅者指南(在小型 PR 上折叠)审阅者指南调整每日 SP 活动行为:当 SP 已运行完成或无法执行时,将任务延后到下一天,而不是以错误结束;并为由人工接管(human-takeover)触发的完成条件增加显式处理。 文件级变更
可能关联的 Issue
技巧与命令与 Sourcery 交互
自定义你的体验访问你的 控制面板 以:
获取帮助Original review guide in EnglishReviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts daily SP campaign behavior so that when SP runs are already completed or cannot be executed, the task is delayed to the next day instead of stopping with an error, and adds explicit handling for human-takeover-triggered completion conditions. File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我给出了一些高层次的反馈:
- 新增的
except RequestHumanTakeover代码块会无条件地把这个信号转换成一次延迟并直接return,这改变了之前的控制流语义;建议在注释中澄清(或者缩小异常捕获范围),说明吞掉这个异常在所有run()调用点上都是有意且安全的。 - “延迟到下一天”的逻辑现在在
RequestHumanTakeover处理逻辑和run_count == 0分支中都各自实现了一遍;建议抽取成一个小的辅助函数(例如_delay_to_next_day(reason)),以保持行为一致并简化后续修改。
给 AI 代理的提示
Please address the comments from this code review:
## Overall Comments
- The new `except RequestHumanTakeover` block unconditionally converts that signal into a delay and `return`, which changes the previous control flow semantics; consider clarifying in a comment (or narrowing the exception scope) that swallowing this exception is intentionally safe for all `run()` call sites.
- The logic for delaying to the next day is now duplicated in the `RequestHumanTakeover` handler and the `run_count == 0` branch; consider refactoring to a small helper (e.g., `_delay_to_next_day(reason)`) to keep behavior consistent and simplify future changes.帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've left some high level feedback:
- The new
except RequestHumanTakeoverblock unconditionally converts that signal into a delay andreturn, which changes the previous control flow semantics; consider clarifying in a comment (or narrowing the exception scope) that swallowing this exception is intentionally safe for allrun()call sites. - The logic for delaying to the next day is now duplicated in the
RequestHumanTakeoverhandler and therun_count == 0branch; consider refactoring to a small helper (e.g.,_delay_to_next_day(reason)) to keep behavior consistent and simplify future changes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `except RequestHumanTakeover` block unconditionally converts that signal into a delay and `return`, which changes the previous control flow semantics; consider clarifying in a comment (or narrowing the exception scope) that swallowing this exception is intentionally safe for all `run()` call sites.
- The logic for delaying to the next day is now duplicated in the `RequestHumanTakeover` handler and the `run_count == 0` branch; consider refactoring to a small helper (e.g., `_delay_to_next_day(reason)`) to keep behavior consistent and simplify future changes.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request modifies the run method in campaign_sp.py to handle RequestHumanTakeover exceptions and changes the task completion logic to delay the task to the next day even if it fails to execute. A review comment identifies a significant logic flaw where task interruptions (via TaskEnd) could lead to tasks being incorrectly delayed to the next day if no runs were completed. The reviewer suggested a refactored implementation to correctly handle task switching and consolidate the delay logic.
| except TaskEnd: | ||
| # Catch task switch | ||
| pass | ||
| except RequestHumanTakeover: | ||
| # Daily SP already completed, delay to next day | ||
| logger.info('Daily SP already completed or unable to enter') | ||
| logger.info('Delaying task to next day') | ||
| self.config.task_delay(server_update=True) | ||
| return | ||
|
|
||
| # Check if SP was successfully executed | ||
| if self.run_count > 0: | ||
| # SP completed successfully, delay to next day | ||
| logger.info(f'SP completed successfully, run_count={self.run_count}') | ||
| self.config.task_delay(server_update=True) | ||
| else: | ||
| self.config.task_stop() | ||
| # SP failed to execute (possibly already completed today) | ||
| # Delay task to next day instead of stopping | ||
| logger.info('SP failed to execute, possibly already completed today') | ||
| logger.info('Delaying task to next day') | ||
| self.config.task_delay(server_update=True) |
There was a problem hiding this comment.
目前的逻辑在处理 TaskEnd(任务切换)时存在缺陷。如果任务因为更高优先级的任务中断(例如委托),此时 run_count 为 0,代码会继续执行到第 34 行并调用 task_delay,导致该任务被错误地推迟到第二天,从而导致今天不再尝试运行该任务。
建议在捕获 TaskEnd 时,如果任务未完成,应通过 task_stop() 重新抛出异常以维持正常的任务调度。同时,可以简化重复的延时逻辑,使代码更整洁。
except TaskEnd:
if self.run_count > 0:
self.config.task_delay(server_update=True)
self.config.task_stop()
except RequestHumanTakeover:
logger.info('Daily SP already completed or unable to enter')
if self.run_count > 0:
logger.info(f'SP completed successfully, run_count={self.run_count}')
else:
logger.info('SP failed to execute, possibly already completed today')
self.config.task_delay(server_update=True)
现在5次重试后会报错停止alas,改成了会延时然后运行其他任务
Summary by Sourcery
Bug Fixes:
Original summary in English
Summary by Sourcery
Bug Fixes: