Skip to content

活动每日sp如果已经打完则延时#146

Merged
Beatrice-betty merged 1 commit into
wess09:devfrom
Beatrice-betty:dev
May 23, 2026
Merged

活动每日sp如果已经打完则延时#146
Beatrice-betty merged 1 commit into
wess09:devfrom
Beatrice-betty:dev

Conversation

@Beatrice-betty
Copy link
Copy Markdown
Collaborator

@Beatrice-betty Beatrice-betty commented May 22, 2026

现在5次重试后会报错停止alas,改成了会延时然后运行其他任务

Summary by Sourcery

Bug Fixes:

  • 防止每日活动 SP 任务在多次尝试失败后因错误而中止:当 SP 已经完成或无法进入时,将其延迟到下一天再执行。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Prevent the daily campaign SP task from stopping with an error after multiple failed attempts by delaying it to the next day when SP is already completed or cannot be entered.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 22, 2026

审阅者指南(在小型 PR 上折叠)

审阅者指南

调整每日 SP 活动行为:当 SP 已运行完成或无法执行时,将任务延后到下一天,而不是以错误结束;并为由人工接管(human-takeover)触发的完成条件增加显式处理。

文件级变更

变更 详情 文件
在 SP 运行过程中处理 RequestHumanTakeover,通过将任务延迟到下一天而不是失败。
  • 在 run 方法中捕获 RequestHumanTakeover 异常
  • 记录日志说明每日 SP 已完成或无法进入
  • 调用 task_delay,传入参数 server_update=True,并在处理异常后立即返回
module/event/campaign_sp.py
统一运行后的结果处理,使所有 SP 非成功或部分成功场景都改为将任务延迟到下一天,而不是停止任务。
  • 在 SP 成功完成且 run_count > 0 时,在延迟前增加日志记录
  • 将 run_count == 0 时的 task_stop 替换为 task_delay,并添加说明性日志
  • 在注释中说明:失败或已完成状态会导致任务延迟,而不是停止任务
module/event/campaign_sp.py

可能关联的 Issue

  • #(未指定):本 PR 修改了在活动 SP 已完成时的行为,将其改为延迟到下一天,从而解决重复报错问题。
  • #0:该 PR 针对活动每日 SP 已完成或无法进入时的处理逻辑,正是 Issue 中报错场景。

技巧与命令

与 Sourcery 交互

  • 触发一次新的审查: 在 Pull Request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub Issue: 通过回复某条审查评论,要求 Sourcery 基于该评论创建一个 issue。你也可以直接回复该评论 @sourcery-ai issue 来创建 issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题的任意位置写上 @sourcery-ai,即可随时生成标题。你也可以在 Pull Request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 Pull Request 摘要: 在 Pull Request 正文任意位置写上 @sourcery-ai summary,即可在该位置生成 PR 摘要。你也可以在 Pull Request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 Pull Request 中评论 @sourcery-ai guide,即可(重新)生成审阅者指南。
  • 一次性解决所有 Sourcery 评论: 在 Pull Request 中评论 @sourcery-ai resolve,即可将所有 Sourcery 评论标记为已解决。如果你已经处理完所有评论但不想再看到它们,这会很有用。
  • 一次性关闭所有 Sourcery 审查: 在 Pull Request 中评论 @sourcery-ai dismiss,即可关闭现有的所有 Sourcery 审查。尤其适用于你想从一次全新的审查开始的场景——别忘了再评论 @sourcery-ai review 来触发新的审查!

自定义你的体验

访问你的 控制面板 以:

  • 启用或禁用审查功能,例如 Sourcery 自动生成的 Pull Request 摘要、审阅者指南等。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查指令。
  • 调整其他审查设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts 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

Change Details Files
Handle RequestHumanTakeover during SP run by delaying the task to the next day instead of failing.
  • Catch RequestHumanTakeover exceptions in the run method
  • Log that daily SP is already completed or cannot be entered
  • Call task_delay with server_update=True and return immediately after handling the exception
module/event/campaign_sp.py
Unify post-run outcomes so that all SP non-success or partial-success scenarios delay the task to the next day rather than stopping it.
  • Add logging when SP completes successfully with run_count > 0 before delaying
  • Replace task_stop when run_count == 0 with task_delay and explanatory logs
  • Document in comments that failures or already-completed states cause a delay instead of stopping the task
module/event/campaign_sp.py

Possibly linked issues

  • #(not specified): PR changes Event SP behavior when already completed to delay to next day, addressing the repeated-failure issue.
  • #0: 该PR针对活动每日SP已完成或无法进入时的处理逻辑,正是Issue中报错场景。

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sourcery 对开源项目免费 —— 如果你喜欢我们的评审,请考虑分享给更多人 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 19 to +39
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

目前的逻辑在处理 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)

@Beatrice-betty Beatrice-betty merged commit 28674c2 into wess09:dev May 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant