Files
Auto_Bangumi/docs/dev/plugins/points/scheduled-task.md
Estrella Pan 3258fcca4b docs(4.0-P7): 插件开发文档拆分为总览加每个扩展点一页,补齐中英日三语
- docs/dev/plugins.md 改为总览与导航,旧内容拆入 docs/dev/plugins/
- 新增核心概念、配置表单、事件、前端挂载点、命令行、签名与分发、内置插件、示例页
- 每个扩展点一页,侧边栏由页面表生成
- 改正旧文档中下载器配置、hardlink path_map 与补链按钮的过时描述
2026-10-08 14:51:00 +02:00

26 lines
910 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 定时任务(scheduled_task)
增加一个周期执行的后台任务。`@provider(points.SCHEDULED_TASK, id=...)` 返回 `ScheduledTask`。
```python
from ab_sdk.tasks import ScheduledTask
@provider(points.SCHEDULED_TASK, id="sync")
def sync(self):
async def run() -> None:
...
return ScheduledTask(run, interval=lambda: self.config.interval, initial_delay=60)
```
| 字段 | 说明 |
| --- | --- |
| `run` | 无参数的异步函数 |
| `interval` | 两次执行之间的间隔(秒)。可以是函数,每轮重新读取,以便跟随配置变化 |
| `initial_delay` | 首次执行前先等待的秒数,默认 0 |
| `enabled` | 可选的函数,返回 `False` 时本轮跳过 |
- 任务只在程序运行时执行,与 RSS 刷新等内置任务一同启停。
- `run` 抛出的异常计入插件熔断。
- 间隔从上一次执行结束时算起,不是固定节拍。