> For the complete documentation index, see [llms.txt](https://babyqdoc.gitbook.io/wechatdocs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://babyqdoc.gitbook.io/wechatdocs/ding-shi-ren-wu/tian-jia-ding-shi-ren-wu.md).

# 添加定时任务

1 内置定时模块 全平台运行&#x20;

2 支持Cron表达式&#x20;

3 支持任务执行次数&#x20;

4 ...

**使用起来非常灵活,使用场景考也考虑了不少 如 1⃣️每日的问候 早安晚安 2⃣️ 执行指定次数并销毁任务 3⃣️ 执行任意系统命令(基于lua os模块) 自动化运维将会非常的方便 ..**

**原理：通过定时执行 `CronSchedules`文件夹下的任意脚本任意方法这样设计扩展起来也比较灵活**

**在 `CronSchedules` 目录下建立任意lua文件名作为任务调用执行的文件 任务的函数名任意 但是必须包含2个参数 如建立一个文件名为`CronDemo1.lua` 函数为TaskOne(Wxid, task)**

{% hint style="info" %}
添加定时任务

<http://127.0.0.1:8898/v1/LuaApiCaller?funcname=AddCrons\\&timeout=10\\&wxid=wxid12345678>

POST JSON

{"Wxid":"Wxid123455678","Sepc":"\*/5 \* \* \* \* ?","FileName":"CronDemo1.lua","FuncName":"**TaskOne**"}

获取定时任务

GET

<http://127.0.0.1:8898/v1/LuaApiCaller?funcname=GetCrons\\&timeout=10\\&wxid=wxid12345>

删除定时任务

<http://127.0.0.1:8898/v1/LuaApiCaller?funcname=DelCrons\\&timeout=10\\&wxid=wxid12345>

POST JSON

{"TaskID":2}
{% endhint %}
