home / skills / aster110 / mycc / scheduler

scheduler skill

/.claude/skills/scheduler

This skill helps you manage and run automated tasks with the built-in scheduler in the mycc backend, triggering tasks and recording history.

npx playbooks add skill aster110/mycc --skill scheduler

Review the files below or copy the command above to add this skill to your agents.

Files (4)
SKILL.md
3.0 KB
---
name: scheduler
description: 定时任务系统。内置在 mycc 后端,自动执行定时任务。触发词:"/scheduler"、"定时任务"、"启动定时"、"查看定时"
---

# 定时任务系统

定时任务功能**内置在 mycc 后端**,启动后端后自动生效。

## 触发词

- "/scheduler"
- "定时任务"
- "启动定时"
- "查看定时任务"
- "设置定时任务"

---

## 工作原理

```
mycc 后端启动
    ↓
scheduler 模块自动启动
    ↓
每分钟检查 tasks.md
    ↓
匹配时间 → 调用 Claude 执行任务
    ↓
执行完成 → 记录到 history.md + 发通知
```

**关键点**:
- 定时任务是 mycc 后端的一部分
- 后端运行 = 定时任务运行
- 后端停止 = 定时任务停止
- `history.md` 会自动创建,无需手动

---

## 任务配置

位置:`.claude/skills/scheduler/tasks.md`

### 时间格式

| 类型 | 格式 | 示例 |
|------|------|------|
| 每日 | `HH:MM` | `08:00`、`22:30` |
| 每周 | `周X HH:MM` | `周一 09:00`、`周日 20:00` |
| 一次性 | `YYYY-MM-DD HH:MM` | `2026-02-01 10:00` |
| 间隔 | `每X分钟` / `每X小时` | `每30分钟`、`每2小时` |

### 表格格式

```markdown
| 时间 | 任务 | Skill | 说明 |
|------|------|-------|------|
| 08:00 | 每日初始化 | /morning | 更新日期 |
| 每2小时 | 健康提醒 | /tell-me | 喝水活动 |
| 23:40 | 清理任务 | - | 删除过期一次性任务 |
```

### 注意事项

- **Skill 列**:填 skill 名称(如 `/tell-me`),无特定 skill 填 `-`
- **说明列**:传给 AI 的任务描述,可以写详细需求
- **时间误差**:允许 ±2 分钟
- **间隔任务**:对齐到整点/整分钟(如 每2小时 = 0/2/4/6/8/10/12/14/16/18/20/22 点)

---

## 用户操作

| 用户说 | AI 执行 |
|--------|----------|
| "启动定时任务" | 执行 `/mycc` 启动后端 |
| "停止定时任务" | 停止后端 |
| "查看定时任务" | 读取并显示 tasks.md |
| "添加定时任务 xxx" | 编辑 tasks.md 添加一行 |
| "每天 9 点提醒我 xxx" | 添加 `\| 09:00 \| xxx \| /tell-me \| ... \|` |

---

## 执行历史

位置:`.claude/skills/scheduler/history.md`(自动创建)

自动记录每次任务执行:
- 开始时间
- 任务名称
- 执行状态(成功/失败)

---

## 依赖

| Skill | 用途 | 必须? |
|-------|------|--------|
| `/tell-me` | 发送飞书通知 | 推荐 |
| `/mycc` | 启动后端 | 必须 |

如果没有 `/tell-me` skill,任务仍可执行,但不会发通知。

---

## 常见问题

**Q: 定时任务没有执行?**
1. 检查后端是否在运行:`lsof -i :8080`
2. 检查 tasks.md 时间格式是否正确
3. 查看 history.md 确认是否有执行记录

**Q: 收不到飞书通知?**
1. 检查 `/tell-me` skill 是否配置正确
2. 检查飞书 webhook 是否有效

**Q: 后端重启后任务会重新执行吗?**
不会。每个时间点只执行一次,重启后不会补执行已过的任务。

---

## 安装/升级

详见 [SOP.md](./SOP.md)

Overview

This skill is a built-in scheduler for the mycc backend that automatically runs defined tasks on a schedule. When the mycc backend is running, the scheduler starts and checks the task file every minute to trigger tasks, log results, and optionally send notifications. It stores execution history automatically and requires no separate daemon.

How this skill works

On backend startup the scheduler module launches and scans .claude/skills/scheduler/tasks.md every minute. When a time or interval matches a task row the scheduler calls the specified skill or invokes Claude to execute the task. Results and status (success/failure) are appended to .claude/skills/scheduler/history.md and notifications are sent if a notification skill is configured.

When to use it

  • Run recurring automations (daily reports, reminders, maintenance)
  • Fire one-off tasks at a specific future datetime
  • Schedule interval-based checks (every X minutes/hours)
  • Trigger skills at defined weekday times (weekly jobs)
  • Record execution history and audit scheduled runs

Best practices

  • Keep tasks.md lines concise and include the target skill in the Skill column or use '-' when none is needed
  • Use clear descriptions in the notes/description column — this text is sent to the AI as the task prompt
  • Prefer recommended /tell-me for notifications so you receive execution alerts
  • Validate time formats and mind the ±2 minute scheduling tolerance
  • Align interval tasks to minute/hour boundaries (e.g., every 2 hours runs on 0/2/4…)

Example use cases

  • Daily 08:00: run a morning initialization skill to update date-specific state
  • Every 2 hours: trigger a hydration reminder via /tell-me
  • Weekly on Monday 09:00: generate and send a weekly status report
  • One-time scheduled migration at 2026-02-01 10:00 to run a maintenance script
  • 23:40 daily cleanup task to remove expired one-time entries from tasks.md

FAQ

Why didn’t a scheduled task run?

Confirm the mycc backend is running, check tasks.md for correct time format, and inspect history.md for any execution records or errors.

Will tasks run if /tell-me is not available?

Yes. Tasks still execute, but you will not receive notification messages without a configured notification skill like /tell-me.

If the backend restarts, do missed tasks run retroactively?

No. Each scheduled time is executed only once. Tasks that were missed during downtime are not re-run automatically after restart.