SuperAPI AI Directory

cron-manager

Data & analytics

View repository

Updated 10-15 20:28

About this skill

Scheduled Task Management

Manage CountBot's scheduled task system via the command line, supporting full CRUD operations and session data management.

Use Cases

  • User says "remind me about the meeting every day at 9 AM" -> create a scheduled task
  • User says "help me set up a task to check the weather every hour" -> create a scheduled task
  • User says "show me what scheduled tasks I have" -> list tasks
  • User says "change that weather task to run every 2 hours" -> modify a task
  • User says "delete that news task" -> delete a task
  • User says "pause/resume a certain task" -> disable/enable a task
  • User says "run that task once right now" -> manual trigger
  • User says "show me the history messages of the weather task" -> view session messages
  • User says "clean up the history records of scheduled tasks" -> clean up session

Command-Line Usage

Before starting, quickly confirm the backend is available:

curl -s http://127.0.0.1:8000/api/cron/jobs || echo "后端服务没在运行!"

For all operations, prioritize using the exec tool to execute this script:

python3 skills/cron-manager/scripts/cron_manager.py <command> [args]

Hard Rules:

  • Only use skills/cron-manager/scripts/cron_manager.py this script name; do not guess cron.py
  • info/delete/enable/disable/run/messages/clean/reset always prioritize passing positional arguments <job_id>
  • Do not first ls, then help, then try and fail multiple times; prioritize directly executing the accurate commands below
  • Only when a command returns an argument error, add a single -h to view help

Create Task

# 基本创建(默认启用自动重试1次)
python3 skills/cron-manager/scripts/cron_manager.py create --name "每日天气" --schedule "0 9 * * *" --message "查询今天的天气并生成播报"

# 创建不重试的任务
python3 skills/cron-manager/scripts/cron_manager.py create --name "简单任务" --schedule "0 9 * * *" --message "执行简单任务" --max-retries 0

# 创建并推送到当前渠道(多机器人渠道应同时指定 account_id)
python3 skills/cron-manager/scripts/cron_manager.py create --name "每日天气" --schedule "0 9 * * *" --message "查询今天的天气并生成播报" --channel feishu --account-id bot --chat-id ou_xxxx --deliver

# 创建带自定义重试的任务(失败后最多重试 3 次,每次间隔 60 秒)
python3 skills/cron-manager/scripts/cron_manager.py create --name "重要任务" --schedule "0 9 * * *" --message "执行重要任务" --max-retries 3 --retry-delay 60

# 创建一次性任务(成功后自动删除)
python3 skills/cron-manager/scripts/cron_manager.py create --name "一次性提醒" --schedule "0 14 * * *" --message "下午2点提醒" --delete-on-success

List Tasks

curl -s http://127.0.0.1:8000/api/cron/jobs || echo "后端服务没在运行!"

# 需要更易读的格式时再用脚本
python3 skills/cron-manager/scripts/cron_manager.py list

View Task Details

python3 skills/cron-manager/scripts/cron_manager.py info <job_id>

Modify Task

# 修改调度时间
python3 skills/cron-manager/scripts/cron_manager.py update <job_id> --schedule "0 */2 * * *"

# 修改名称
python3 skills/cron-manager/scripts/cron_manager.py update <job_id> --name "新名称"

# 修改执行消息
python3 skills/cron-manager/scripts/cron_manager.py update <job_id> --message "新的执行指令"

# 修改渠道投递(注意:update 的 --deliver 需要显式写 true/false)
python3 skills/cron-manager/scripts/cron_manager.py update <job_id> --channel telegram --account-id default --chat-id 123456 --deliver true

Delete Task

python3 skills/cron-manager/scripts/cron_manager.py delete <job_id>

Enable/Disable Task

python3 skills/cron-manager/scripts/cron_manager.py enable <job_id>
python3 skills/cron-manager/scripts/cron_manager.py disable <job_id>

Manual Trigger Execution

python3 skills/cron-manager/scripts/cron_manager.py run <job_id>

Validate Cron Expression

python3 skills/cron-manager/scripts/cron_manager.py validate "0 9 * * *"

Batch Create Tasks

# 从 JSON 文件批量创建任务
python3 skills/cron-manager/scripts/cron_manager.py batch-create --file tasks.json

JSON File Format Example:

[
  {
    "name": "每日天气",
    "schedule": "0 9 * * *",
    "message": "查询今天的天气",
    "enabled": true,
    "max_retries": 3,
    "retry_delay": 60
  },
  {
    "name": "每周报告",
    "schedule": "0 10 * * 1",
    "message": "生成本周工作报告",
    "enabled": true,
    "delete_on_success": false
  }
]

Batch Delete Tasks

# 批量删除多个任务(支持 ID 前缀匹配)
python3 skills/cron-manager/scripts/cron_manager.py batch-delete abc123 def456 ghi789

View Task Session Messages

python3 skills/cron-manager/scripts/cron_manager.py messages <job_id> --limit 20

Clean Up Task Session Messages

# 保留最近10条
python3 skills/cron-manager/scripts/cron_manager.py clean <job_id> --keep 10

# 清空所有消息
python3 skills/cron-manager/scripts/cron_manager.py clean <job_id> --keep 0

Reset Task Session

python3 skills/cron-manager/scripts/cron_manager.py reset <job_id>

Cron Expression Reference

Format: 分钟 小时 日 月 星期

Expression Meaning
0 9 * * * Every day at 9:00
*/30 * * * * Every 30 minutes
0 9 * * 1-5 Weekdays at 9:00
0 0 1 * * Day 1 of every month at 0:00
0 */2 * * * Every 2 hours on the hour
0 8,12,18 * * * Every day at 8:00, 12:00, 18:00

Notes

  • job_id supports prefix matching, so you can enter just the first few characters
  • Built-in system tasks are completely hidden, invisible and non-operable
  • The message field is the instruction sent to the AI when the task executes; it should clearly state what to do
  • Prioritize running curl -s http://127.0.0.1:8000/api/cron/jobs || echo "后端服务没在运行!"first to confirm the backend is online
  • It is strictly forbidden to write the script name as cron.py; the standard entry point is cron_manager.py
  • For commands that accept job_id , use only positional arguments, do not write --id
  • create for --deliver is a no-argument switch;update for --deliver must be written as true or false
  • When creating a task, if the result needs to be pushed to a channel, you must specify --deliver
  • Multi-bot channels (such as Feishu) must distinguish --account-id, otherwise it will default to default
  • When executed in a session with channel context, the script automatically fills in the current channel/chat_id/account_id
  • The clean operation is irreversible; before cleaning, it is recommended to first use messages to view the content
  • reset deletes the entire session, and a new session will be automatically created the next time the task runs

New Feature Description

Automatic Retry Mechanism

  • Automatic retry is enabled by default; after a failure, it retries once with an interval of 60 seconds
  • Use --max-retries to specify the maximum number of retries (0 = no retry, maximum 5)
  • Use --retry-delay to specify the retry interval in seconds (default 60 seconds)
  • After a task fails, it will automatically retry until it succeeds or the maximum number of retries is reached
  • During retries, the task status is shown as "retrying"
  • After retries are exhausted, execution continues according to the original cron expression

Automatically deleted after success

  • Use --delete-on-success to mark a task as a one-time task
  • After the task executes successfully, it will be automatically deleted from the database
  • Suitable for one-time reminders, temporary tasks, and similar scenarios
  • If the task fails, it will not be deleted and will be handled according to the retry policy

Batch Operations

  • batch-create supports batch creation of tasks from a JSON file
  • batch-delete supports deleting multiple tasks at once
  • Batch operations display statistics for successes and failures
  • Partial failures do not affect the processing of other tasks

Automatic Channel Identification

When a user converses with the AI through channels such as Feishu, DingTalk, QQ, Telegram, etc., the system prompt automatically includes the current channel information:

Channel: feishu
Chat ID: ou_xxxx
Account ID: bot

When creating scheduled tasks, this information should be actively used:

  • If the user says "remind me every day", automatically use the current channel and chat_id as the delivery target
  • If the current channel supports multiple bots, the current Account ID
  • If the user says "push to this group", get the channel and chat_id from the context
  • If it is a web-based conversation (no channel information), do not set delivery when creating the task; execute only within the system

Example: A user says in a Feishu group, "Remind me to check the weather at 9 AM every day"

python3 skills/cron-manager/scripts/cron_manager.py create --name "每日天气提醒" --schedule "0 9 * * *" --message "查询今天的天气并生成播报" --channel feishu --account-id bot --chat-id ou_xxxx --deliver