为什么要用定时任务?

很多运营工作是重复的:每天发日报、每周检查死链、每月清理过期数据、每隔几小时刷新缓存。这些事情不难,但每次都要人工触发就很烦。
OpenClaw 内置了定时任务系统(Cron),可以让 AI 按照你设定的时间自动执行工作。设置一次,之后就是全自动。
这篇教程从最简单的一次性提醒开始,一步步教你掌握 OpenClaw 的定时任务功能。
三种调度类型
OpenClaw 支持三种时间调度方式,覆盖不同场景:
at——一次性任务
到了指定时间执行一次,执行完自动删除。适合提醒、倒计时类任务。
# 20 分钟后提醒我检查文档
openclaw cron add \
--name "检查文档提醒" \
--at "20m" \
--session main \
--system-event "提醒:去检查一下文档发布情况" \
--delete-after-run
every——固定间隔
每隔固定时间执行一次,不关心具体几点。适合轮询、心跳类任务。
# 每 6 小时检查一次网站是否正常
openclaw cron add \
--name "网站健康检查" \
--every "6h" \
--session isolated \
--agent-turn "检查 361sale.com 是否正常访问,如果有异常立即告警"
cron——标准表达式
最灵活的方式,用 5 位 cron 表达式精确控制执行时间。适合”每天早上 9 点””每周一上午 10 点”这种精确需求。
# 每天早上 9 点生成日报
openclaw cron add \
--name "每日日报" \
--cron "0 9 * * *" \
--tz "Asia/Shanghai" \
--session isolated \
--agent-turn "生成昨天的运营数据摘要"
cron 表达式格式:分 时 日 月 周。常用示例:
0 9 * * *→ 每天 9:000 9 * * 1→ 每周一 9:000 */6 * * *→ 每 6 小时整点30 8 1 * *→ 每月 1 号 8:30
创建一次性提醒
最简单的用法——设置一个定时提醒:
openclaw cron add \
--name "会议提醒" \
--at "2026-05-20T14:00:00+08:00" \
--session main \
--system-event "提醒:14:00 有产品评审会议" \
--wake now \
--delete-after-run
Parameter Explanation:
--at:具体时间点(ISO 8601 格式),不带时区按 UTC 算--session main:在主会话中执行(你会在当前对话里看到提醒)--system-event:提醒内容--wake now:立即唤醒会话处理这个事件--delete-after-run:执行完自动删除这个 job
也支持相对时间:--at "30m"(30 分钟后)、--at "2h"(2 小时后)。
创建每日重复任务
比如每天早上 9 点让 AI 检查网站收录情况:
openclaw cron add \
--name "每日收录检查" \
--cron "0 9 * * *" \
--tz "Europe/Berlin" \
--session isolated \
--agent-turn "检查 361sale.com 在 Google 的最新收录情况,列出昨天新收录的页面和未收录的页面。"
expense or outlay --tz 指定时区很重要。如果你在柏林,用 Europe/Berlin;在上海,用 Asia/Shanghai。不设时区默认按服务器本地时区。
配置执行方式

OpenClaw 的 cron job 有四种执行方式:
- main:在你的主对话会话中执行。适合提醒类任务,你会直接在对话里看到结果。只能用 system-event 类型。
- isolated(推荐):在独立的临时会话中执行。不会干扰你的主对话,执行完会话自动清理。
- current:绑定到创建时的当前会话。适合需要上下文的重复任务。
- session:自定义ID:在一个持久化的命名会话中执行。适合需要积累历史的工作流。
大部分场景用 isolated 就够了。只有需要 AI 记住上次执行结果时,才用 session:xxxThe
配置 Delivery 推送结果
执行完之后,你可能想把结果推送到某个地方:
openclaw cron add \
--name "周报生成" \
--cron "0 10 * * 1" \
--tz "Asia/Shanghai" \
--session isolated \
--agent-turn "生成上周的 SEO 周报,包括流量趋势、排名变化、新增收录。" \
--delivery announce \
--delivery-channel telegram \
--delivery-to "-100123456789"
delivery 支持三种模式:
- announce:推送到聊天渠道
- webhook:POST 到指定 URL
- none:不推送,只在任务记录里留痕
管理定时任务
创建完 job 后,日常管理用这几个命令:
# 列出所有 job
openclaw cron list
# 查看某个 job 详情
openclaw cron get <job-id>
# 查看执行历史
openclaw cron runs --id <job-id>
# 手动触发一次(测试用)
openclaw cron run <job-id>
# 暂停一个 job(不删除)
openclaw cron update <job-id> --enabled false
# 恢复
openclaw cron update <job-id> --enabled true
# 删除
openclaw cron remove <job-id>
建议每次创建新 job 后,先用 openclaw cron run 手动触发一次,确认执行正常再等自动调度。
用 JSON5 文件管理复杂任务
如果你的任务配置比较复杂,用命令行参数写起来太长,可以写成 JSON5 文件:
// daily-seo-check.json5
{
name: "每日 SEO 巡检",
schedule: {
kind: "cron",
expr: "0 8 * * *",
tz: "Europe/Berlin"
},
payload: {
kind: "agentTurn",
message: "执行每日 SEO 巡检:1) 检查网站是否正常访问;2) 检查昨天发布的文章是否被收录;3) 检查是否有 5xx 错误;4) 检查核心关键词排名变化。输出简洁报告。",
timeoutSeconds: 180
},
delivery: {
mode: "announce",
channel: "telegram",
to: "-100123456789"
},
sessionTarget: "isolated"
}
然后一行命令导入:
openclaw cron add --file daily-seo-check.json5
common problems
Q1:cron 表达式写错了怎么办?
expense or outlay openclaw cron update <job-id> --cron "新表达式" 修改。或者直接编辑 ~/.openclaw/cron/jobs.json 文件,Gateway 会自动检测变化。
Q2:Gateway 重启后定时任务会丢失吗?
不会。所有 job 持久化在 ~/.openclaw/cron/jobs.json,重启后自动恢复。运行状态在 jobs-state.json 里。
Q3:任务执行超时怎么办?
在 payload 里设置 timeoutSeconds。默认值可能不够复杂任务使用,建议设 120-300 秒。超时后任务会被标记为 timed_out。
Q4:怎么知道任务有没有正常执行?
expense or outlay openclaw cron runs --id <job-id> 查看历史。每次执行都有状态记录:succeeded、failed、timed_out。也可以用 openclaw tasks audit 做整体健康检查。
Q5:能不能设置任务失败后自动告警?
可以。在 job 配置里加 failureAlert 字段,指定连续失败几次后告警、告警发到哪里。
Q6:isolated 会话执行完后数据还在吗?
执行记录保留 7 天,之后自动清理。如果你需要长期保留执行结果,用 delivery 推送到外部渠道,或者用 session:xxx 模式让 AI 在持久会话里积累历史。
相关教程推荐
- OpenClaw 怎么做内容排期?把关键词研究变成可执行的发布计划
- OpenClaw 怎么做数据分析日报?每天 5 分钟掌握网站运营状态
- OpenClaw 怎么做 SEO 关键词研究?从找词、分类到内容规划的实操教程
summarize
OpenClaw 的定时任务功能让你把所有重复性工作自动化:一次性提醒用 at,固定间隔用 every,精确时间用 cron 表达式。配合 delivery 推送,执行结果自动发到你的群里。
核心就是:选对调度类型 → 写好 AI 指令 → 配好推送 → 测试一次确认正常。之后就是全自动。
更多定时任务高级用法,参考官方文档:OpenClaw Scheduled Tasks 文档The
官方文档:OpenClaw 定时任务配置文档
Link to this article:https://www.361sale.com/en/87568/The article is copyrighted and must be reproduced with attribution.













March 11, 13:490
Now definitely still do SEO, just play changed. Previously rely on heaps of content, heaps of keywords can have traffic, and now pay more attention to the quality of content + brand trust + user experience. In addition to relying solely on SEO is actually more and more difficult, a lot of good basically SEO + social media + content marketing + private domain conversion to do together. SEO is still a long-term customer acquisition channel, but can no longer be taken as the only channel.Hehe is working.
March 11, 10:540
Normal, included only on behalf of Google to see the page, does not mean that the ranking immediately, "has been included but not ranked" usually because: Keyword competition, page weight is low, the content is not strong enough, the page is relatively new. Continue to optimize the long-tail keywords, content quality and internal chain, usually takes a little time, the ranking will slowly come out!Amelia Foster March 6, 16:200
Do you have a screenshot?lit. even a son who is not a fish knows the joy of fish March 6, 09:230
Don't pile on the optimization plugins first, locate the bottlenecks first: Use Query Monitor to see slow SQL, slow hooks. Pause all plugins for comparison, then turn them on one by one. Check autoload is too big (options table). Check database indexes with large table queries. Tackle host/database performance first if server TTFB is high.Hehe is working.
March 3, 16:470
Hi Windjammer, there's really no need to mess with complicated local environments, regular people follow these steps and the update basically won't crash the site 👇 First, backup the whole site, files + database are prepared, this is the bottom line, out of the problem can be a key to go back. Don't change the whole thing in one click, change it in batches, change the unimportant plug-ins first, and then change the core ones. Immediately after the update, clear the cache, go to the foreground to check the home page, article page, buttons, forms, these key positions. It is best to install a plug-in that supports version rollback, in case of a crash, cut back to the old version in a second. To summarize: backup first, change in batches, check after changing, leave a way back, stable ✅😎 Hope this helps!bugbang March 2, 09:550
Usually it's not that the payment didn't work, but that the callback (webhook) didn't write back the order status. Troubleshooting steps: WooCommerce → Status → Logs: see if the payment gateway has webhook error / signature error / timeout Check if the site is blocked by WAF (Cloudflare, Pagoda Firewall, security plugins) Check if "Cache checkout pages/interface paths" is enabled (checkout pages and callback interfaces should not be cached) Look at the server error logs for 500/fatal errors that interrupt the callback execution. Solution: Release wp-json, wc-api, payment gateway callback URLs (configure as per gateway documentation) Disable cache and JS merge compression test on checkout page once If using Cloudflare: set no-challenge, no-block rules for callback URLsUlla Nala Zhenhuan (18嬛嬛嬛) January 31st, 09:360
1) Determine whether it is "Normal Waiting" or "Abnormally Stuck". You can first look at 3 signals: whether the page release time is within 7-14 days, whether there are only a small number of pages with this status, and whether the page has appeared in the XML Sitemap. If all three are satisfied, most likely belong to the normal crawling and evaluation stage, do not need to do it immediately. 2) Under what circumstances is it useless to "wait"? The following cases will not be solved automatically by time: the page has almost no internal links (isolated page), the content is highly similar to the existing pages on the site, canonical points to other URLs, and too many similar articles are published on the same topic for a short period of time. In this case, Google has been crawled, but judged that "it is not worth entering the index". 3) The most effective way of manual intervention (no tossing) Prioritize these 3 things: add internal links, link to the page from related old articles or columns, and enhance the density of information on the first screen. The first 2-3 paragraphs directly answer the user's question, avoid too much padding, confirm canonical as self-referential, avoid being judged as a duplicate page, and then go to GSC to request reindexing after doing so. 4) What "intervention actions" are counterproductive? It is not recommended: frequent deletion and reposting, clicking "request to index" several times in a row, forcing keywords to be stacked for indexing, changing URLs or titles arbitrarily. These operations will allow Google to reassess the stability of the page, but slow down the inclusion. 5) a practical judgment standard If an article: has been crawled, there is no noindex / robots problem, there are at least 1-2 related internal links, the content obviously solves an independent problem, then it is included, just a matter of time, not a plug-in problem.Post Porter January 30th 10:000
The new station does not do external links can be completely, the first content and station structure to do a good job more stable. Only rely on the content can generally get included and part of the long-tail word rankings, but the amount of high competition will be slow. It is recommended to wait for the site stable inclusion, 30-50 quality content, keywords began to enter the top 20/30, and then a small amount of external links, priority brand words/naked chain/citation type, do not come up to chase the number. 👍