Skip to content

fix: 添加定时任务执行策略选项#604

Merged
ikenxuan merged 2 commits intomainfrom
fix-#603
Dec 25, 2025
Merged

fix: 添加定时任务执行策略选项#604
ikenxuan merged 2 commits intomainfrom
fix-#603

Conversation

@ikenxuan
Copy link
Collaborator

@ikenxuan ikenxuan commented Dec 25, 2025

Summary by Sourcery

新功能:

  • 引入任务执行策略选项,使计划任务可以选择使用默认的并发执行方式,或在任务已在运行时跳过本次执行。
Original summary in English

Summary by Sourcery

New Features:

  • Introduce a task execution strategy option allowing either default concurrent execution or a skip-when-running behavior for scheduled tasks.

Summary by CodeRabbit

  • New Features
    • Added task execution policies: "default" (allows concurrent runs) and "skip" (prevents overlapping executions).
    • Tasks now expose execution state and policy type so callers can observe running status.
    • Scheduled tasks configured with "skip" will automatically skip starting a new run if a prior run is still active.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 25, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Adds a TaskExecutionType enum, exposes a task type (DEFAULT | SKIP) and running boolean on Task objects, and enforces a skip-on-running guard for scheduled tasks to avoid overlapping executions.

Changes

Cohort / File(s) Summary
Type Definitions
packages/core/src/types/plugin/task.ts
Added export enum TaskExecutionType { DEFAULT, SKIP }; added type: TaskExecutionType and running: boolean to exported Task interface.
Task Factory
packages/core/src/core/karin/task.ts
Extended TaskOptions with optional `type?: TaskExecutionType
Scheduled Task Runner
packages/core/src/plugin/admin/load.ts
Added guard for tasks with type === TaskExecutionType.SKIP: if task.running is true, log skip and do not start; otherwise set task.running = true before executing and reset in finally.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Scheduler
  participant Task as Task(instance)
  participant Func as TaskFunction
  participant Logger

  Scheduler->>Task: trigger scheduled run
  alt Task.type == SKIP and Task.running == true
    Task->>Logger: log "skipping, already running"
    Scheduler-->>Task: exit (skipped)
  else
    Task->>Task: set running = true
    Task->>Logger: log "start"
    Task->>Func: invoke (await if promise)
    Func-->>Task: result / error
    Task->>Logger: log "complete" or "error"
    Task->>Task: set running = false
    Scheduler-->>Task: exit (finished)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I set a flag and watched the clock,
If busy, I politely block.
Default hops free, skip waits in line,
No double-runs — that feels just fine.
A little hop for tidy time. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title is written in Chinese and describes adding a task execution strategy option. While this matches the actual changes (introducing TaskExecutionType enum with DEFAULT/SKIP modes and related fields), the non-English title may reduce discoverability in English-speaking development contexts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-#603

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ikenxuan ikenxuan linked an issue Dec 25, 2025 that may be closed by this pull request
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ikenxuan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在增强定时任务的管理能力,通过引入可配置的执行策略,解决了任务并发执行可能导致的问题。现在,开发者可以为每个定时任务指定在上次执行尚未完成时,是允许其继续并发执行,还是跳过本次执行以避免资源冲突或数据不一致。

Highlights

  • 定时任务执行策略: 为定时任务引入了新的执行策略选项(type),允许配置任务在上次执行未完成时是并发执行(default)还是跳过本次执行(skip)。
  • 任务运行状态管理: 增加了任务的运行状态(running)标记,用于在执行 skip 策略时判断任务是否正在运行,并确保任务执行完毕后重置状态。

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 25, 2025

审阅者指南

为定时任务新增了可配置的执行策略,允许在「默认并发执行」和「运行中则跳过」两种策略之间进行选择,并将其贯穿到任务创建、类型定义以及调度器运行时行为中。

定时任务中新的跳过执行策略时序图

sequenceDiagram
  participant Scheduler
  participant Task as TaskInstance
  participant TaskFunction as TaskFunction
  participant ErrorHandler

  Scheduler->>Task: cron_trigger()
  alt type is skip and running is true
    Task->>Task: log [定时任务: 上一次任务未完成, 跳过本次执行]
    Scheduler-->>Task: return
  else default or not running
    Task->>Task: running = true
    Task->>Task: log [定时任务: 开始执行]
    Task->>TaskFunction: fnc()
    alt fnc returns Promise
      TaskFunction-->>Task: Promise
      Task->>Task: await Promise
    else fnc returns non Promise
      TaskFunction-->>Task: result
    end
    Task->>Task: log [定时任务: 执行完成]
  end
  rect rgb(230,230,230)
    note over Task,ErrorHandler: 错误处理与清理
    alt error thrown
      Task->>ErrorHandler: taskStart(name, name, error)
      ErrorHandler-->>Task: handled
    end
    Task->>Task: running = false
  end
Loading

更新后的任务调度模型类图

classDiagram
  class TaskOptions {
    <<interface>>
    +string? name
    +boolean? log
    +string? type
  }

  class Task {
    <<interface>>
    +string name
    +string cron
    +Function fnc
    +Log log
    +Job? schedule
    +string type
    +boolean running
  }

  class task {
    <<function>>
    +Task task(string cron, Function fnc, TaskOptions options)
  }

  TaskOptions "1" --> "1" Task : configures
  task --> Task : creates

  class Log {
    <<type>>
    +void call(string message)
  }

  class Job {
    <<type>>
  }

  Task o--> Job : schedule
  Task o--> Log : log
Loading

任务执行策略决策流程图

flowchart TD
  A[触发定时任务] --> B{任务类型}
  B -->|skip| C{running 为 true?}
  B -->|default| E[设置 running 为 true 并执行 fnc]
  C -->|yes| D[日志: 上一次任务未完成, 跳过本次执行]
  C -->|no| E[设置 running 为 true 并执行 fnc]
  E --> F[如果 fnc 返回 Promise 则等待]
  F --> G[日志: 执行完成]
  D --> H[结束]
  G --> I[设置 running 为 false]
  I --> H[结束]
Loading

文件级改动

变更 详情 文件
在任务配置中引入任务执行策略选项,并将其传递到创建的任务对象中。
  • 扩展 TaskOptions,使其接受一个可选的执行策略字段,并对 defaultskip 两种模式的行为进行文档说明。
  • 确保创建的任务实例包含所选的执行策略,当未指定时默认使用 default
  • 在任务实例上初始化一个 running 状态标志,用于跟踪是否有正在执行的实例。
packages/core/src/core/karin/task.ts
更新 Task 类型定义以支持新的执行策略和运行状态。
  • 扩展 Task 接口,增加一个必选的执行策略字段,取值限制为 defaultskip
  • 添加一个布尔值 running 标志,用于表示任务当前是否正在执行。
  • 在 Task 类型中记录两种执行模式的语义说明。
packages/core/src/types/plugin/task.ts
修改定时任务执行逻辑,使其根据 skip 策略和 running 标志来决定是否跳过执行,并确保正确清理状态。
  • 在执行定时任务前,如果策略为 skip 且任务已在运行,则跳过执行并记录日志。
  • 在调用任务函数前将任务的 running 标志设置为 true,并在 finally 块中重置为 false,以同时覆盖成功和报错的路径。
  • 保留现有的任务开始与完成日志以及错误处理行为。
packages/core/src/plugin/admin/load.ts

提示与命令

与 Sourcery 交互

  • 触发新的审阅: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub issue: 在某条审阅评论下回复,请求 Sourcery 从该评论创建 issue。你也可以直接在审阅评论下回复 @sourcery-ai issue 来创建 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写入 @sourcery-ai 即可随时生成标题。你也可以在拉取请求中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成拉取请求摘要: 在拉取请求描述正文任意位置写入 @sourcery-ai summary,即可在对应位置生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary 来在任意时间(重新)生成摘要。
  • 生成审阅者指南: 在拉取请求中评论 @sourcery-ai guide,即可在任意时间(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可标记所有 Sourcery 评论为已解决。适用于你已处理完所有评论且不希望再看到它们的情况。
  • 关闭所有 Sourcery 审阅: 在拉取请求中评论 @sourcery-ai dismiss,即可关闭所有现有的 Sourcery 审阅。尤其适用于你想从头开始新的审阅——别忘了再评论一次 @sourcery-ai review 来触发新审阅!

自定义你的体验

访问你的 控制面板 以:

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

获取帮助

Original review guide in English

Reviewer's Guide

Adds a configurable execution strategy for scheduled tasks, allowing either default concurrent execution or a skip-when-running policy, and wires this through task creation, type definitions, and the scheduler runtime behavior.

Sequence diagram for new skip execution strategy in scheduled tasks

sequenceDiagram
  participant Scheduler
  participant Task as TaskInstance
  participant TaskFunction as TaskFunction
  participant ErrorHandler

  Scheduler->>Task: cron_trigger()
  alt type is skip and running is true
    Task->>Task: log [定时任务: 上一次任务未完成, 跳过本次执行]
    Scheduler-->>Task: return
  else default or not running
    Task->>Task: running = true
    Task->>Task: log [定时任务: 开始执行]
    Task->>TaskFunction: fnc()
    alt fnc returns Promise
      TaskFunction-->>Task: Promise
      Task->>Task: await Promise
    else fnc returns non Promise
      TaskFunction-->>Task: result
    end
    Task->>Task: log [定时任务: 执行完成]
  end
  rect rgb(230,230,230)
    note over Task,ErrorHandler: Error handling and cleanup
    alt error thrown
      Task->>ErrorHandler: taskStart(name, name, error)
      ErrorHandler-->>Task: handled
    end
    Task->>Task: running = false
  end
Loading

Class diagram for updated task scheduling model

classDiagram
  class TaskOptions {
    <<interface>>
    +string? name
    +boolean? log
    +string? type
  }

  class Task {
    <<interface>>
    +string name
    +string cron
    +Function fnc
    +Log log
    +Job? schedule
    +string type
    +boolean running
  }

  class task {
    <<function>>
    +Task task(string cron, Function fnc, TaskOptions options)
  }

  TaskOptions "1" --> "1" Task : configures
  task --> Task : creates

  class Log {
    <<type>>
    +void call(string message)
  }

  class Job {
    <<type>>
  }

  Task o--> Job : schedule
  Task o--> Log : log
Loading

Flow diagram for task execution policy decision

flowchart TD
  A[Trigger scheduled task] --> B{Task type}
  B -->|skip| C{running is true?}
  B -->|default| E[Set running true and execute fnc]
  C -->|yes| D[Log: 上一次任务未完成, 跳过本次执行]
  C -->|no| E[Set running true and execute fnc]
  E --> F[Await fnc if Promise]
  F --> G[Log: 执行完成]
  D --> H[End]
  G --> I[Set running false]
  I --> H[End]
Loading

File-Level Changes

Change Details Files
Introduce a task execution strategy option in task configuration and propagate it to created task objects.
  • Extend TaskOptions to accept an optional execution strategy field with documented behavior for 'default' and 'skip' modes.
  • Ensure created task instances include the chosen execution strategy, defaulting to 'default' when unspecified.
  • Initialize a running state flag on task instances for tracking active executions.
packages/core/src/core/karin/task.ts
Update Task type definitions to support the new execution strategy and running state.
  • Extend the Task interface with a required execution strategy field constrained to 'default' or 'skip'.
  • Add a boolean running flag to represent whether a task is currently executing.
  • Document the semantics of the two execution modes in the Task type.
packages/core/src/types/plugin/task.ts
Modify scheduled task execution logic to honor the 'skip' strategy using a running flag and ensure proper cleanup.
  • Before executing a scheduled task, skip execution and log a message if the strategy is 'skip' and the task is already running.
  • Set the task's running flag to true before invoking the task function and reset it to false in a finally block to handle both success and error paths.
  • Preserve existing logging around task start and completion and the error handling behavior.
packages/core/src/plugin/admin/load.ts

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
Contributor

@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 - 我在这里给出了一些总体反馈:

  • 在调度已有任务(pkgCache)时,建议对新增的 typerunning 属性做规范化处理(例如,如果缺失则将 type 默认设为 'default'running 默认设为 false),这样就不需要依赖它们只能通过 task() 帮助函数初始化,同时也能提升对旧任务定义的向后兼容性。
给 AI Agents 的提示
Please address the comments from this code review:

## Overall Comments
- When scheduling existing tasks (`pkgCache`), consider normalizing the new `type` and `running` properties (e.g., defaulting `type` to `'default'` and `running` to `false` if they are missing) to avoid relying on them being initialized only via the `task()` helper and improve backward compatibility with older task definitions.

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

Hey - I've left some high level feedback:

  • When scheduling existing tasks (pkgCache), consider normalizing the new type and running properties (e.g., defaulting type to 'default' and running to false if they are missing) to avoid relying on them being initialized only via the task() helper and improve backward compatibility with older task definitions.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When scheduling existing tasks (`pkgCache`), consider normalizing the new `type` and `running` properties (e.g., defaulting `type` to `'default'` and `running` to `false` if they are missing) to avoid relying on them being initialized only via the `task()` helper and improve backward compatibility with older task definitions.

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

本次 PR 添加了定时任务的执行策略,实现非常清晰,特别是 try...finally 的使用确保了 running 状态的正确重置,增强了代码的健壮性。我发现了一个可以改进的地方,主要是关于代码风格和可维护性,通过使用枚举类型代替字符串字面量,可以使代码更加健壮和易于理解。具体建议请见文件中的评论。

@github-actions
Copy link
Contributor

你可以通过以下命令安装该版本:

pnpm add https://pkg.pr.new/KarinJS/Karin/node-karin@4f9bf1c -w

@ikenxuan ikenxuan merged commit 7f81df5 into main Dec 25, 2025
3 of 5 checks passed
@ikenxuan ikenxuan deleted the fix-#603 branch December 25, 2025 06:26
@github-actions github-actions bot mentioned this pull request Dec 25, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab42d2f and 4f9bf1c.

📒 Files selected for processing (3)
  • packages/core/src/core/karin/task.ts
  • packages/core/src/plugin/admin/load.ts
  • packages/core/src/types/plugin/task.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/core/src/plugin/admin/load.ts (1)
packages/core/src/core/internal/error.ts (1)
  • errorHandler (65-72)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Sourcery review
  • GitHub Check: publish-temp
🔇 Additional comments (7)
packages/core/src/types/plugin/task.ts (2)

4-10: LGTM! Enum implementation addresses previous feedback.

The TaskExecutionType enum provides type safety and eliminates magic strings, directly addressing the concern raised in the previous review. The values and documentation are clear.


28-35: LGTM! Type-safe task execution state tracking.

The new type and running fields are well-documented and provide the necessary foundation for the skip-when-running behavior implemented elsewhere in the PR.

packages/core/src/core/karin/task.ts (2)

2-2: LGTM! Correct import.

The TaskExecutionType enum is properly imported for use in the task factory.


10-15: LGTM! Flexible type definition.

The union type TaskExecutionType | \${TaskExecutionType}`` allows both enum values and their string equivalents, providing flexibility for plugin authors.

packages/core/src/plugin/admin/load.ts (3)

18-18: LGTM! Correct import.

TaskExecutionType is properly imported for implementing the skip-when-running logic.


217-220: LGTM! Clear skip-when-running guard.

The implementation correctly checks both the execution type and running state before skipping. The log message clearly communicates why the task was skipped.


222-231: LGTM! Proper running flag management with cleanup.

The running flag is correctly set before execution and reliably reset in the finally block, ensuring cleanup even on errors.

Note on race conditions: While the check (line 217) and set (line 222) are not atomic, node-schedule typically executes jobs serially within Node.js's event loop, making concurrent execution unlikely. However, be aware that if cron intervals are extremely short or job execution is instantaneous, there's a theoretical window where multiple jobs could see running = false simultaneously.

Comment on lines +43 to +44
type: (options.type as TaskExecutionType) || TaskExecutionType.DEFAULT,
running: false,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's examine the file at the specified lines
cat -n packages/core/src/core/karin/task.ts | head -60

Repository: KarinJS/Karin

Length of output: 1489


🏁 Script executed:

# Search for TaskExecutionType definition
rg -n "TaskExecutionType" packages/core/src/core/karin/task.ts -A 5 -B 2

Repository: KarinJS/Karin

Length of output: 662


🏁 Script executed:

# Also search for the enum definition across the codebase
rg -n "enum TaskExecutionType\|type TaskExecutionType" --type=ts

Repository: KarinJS/Karin

Length of output: 39


🏁 Script executed:

# Find the types directory and locate the task type definition
fd "task.ts" --type f -path "*/types/plugin/*"

Repository: KarinJS/Karin

Length of output: 225


🏁 Script executed:

# Also search for TaskExecutionType definition
rg -n "TaskExecutionType" --type=ts -A 3 -B 1 | head -50

Repository: KarinJS/Karin

Length of output: 2367


🏁 Script executed:

# Search for actual calls to the task() function to see usage patterns
rg -n "task\s*\(" --type-add='ts:*.ts' -t ts -B 2 -A 2 | head -100

Repository: KarinJS/Karin

Length of output: 406


🏁 Script executed:

# Check the entire TaskExecutionType enum to see all values
cat -n packages/core/src/types/plugin/task.ts

Repository: KarinJS/Karin

Length of output: 1001


Use a type guard instead of a type assertion.

TypeScript already restricts options.type to valid enum values via the TaskExecutionType | \${TaskExecutionType}`` type annotation, preventing arbitrary strings at compile time. However, the type assertion at line 43 removes this type information and accepts any value at runtime without validation. Replace the assertion with explicit type narrowing or a helper function to safely handle both enum and string inputs:

type: (typeof options.type === 'string' 
  ? (options.type as TaskExecutionType) 
  : options.type) || TaskExecutionType.DEFAULT

This maintains type safety while making the intent clearer.

🤖 Prompt for AI Agents
In packages/core/src/core/karin/task.ts around lines 43-44, the code uses a type
assertion for options.type which strips type safety; replace it with an explicit
type guard that checks options.type at runtime (e.g., typeof options.type ===
'string') and then safely maps/casts only when the check passes, otherwise use
the value as-is, with a fallback to TaskExecutionType.DEFAULT; optionally
extract this logic into a small helper function to keep the assignment concise
and maintain type safety.

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