@raphaellcs/auto-tasker
v1.0.0
Published
任务自动化工具 - 定时执行、条件触发、任务编排
Downloads
22
Maintainers
Readme
@claw-dev/auto-tasker
任务自动化工具 - 定时执行、条件触发、任务编排
🚀 功能
- 定时执行:固定间隔或 cron 表达式
- 文件监控:文件变化自动触发任务
- 任务编排:串行或并行执行
- 灵活配置:JSON 配置文件
- 执行日志:清晰的执行状态和输出
📦 安装
npx @claw-dev/auto-tasker📖 快速开始
1. 初始化配置
auto-task init生成 auto-tasker.json 配置文件。
2. 编辑配置
{
"version": "1.0",
"mode": "series",
"tasks": [
{
"name": "备份代码",
"command": "git add . && git commit -m 'auto-backup' && git push",
"interval": 3600000
}
]
}3. 运行任务
# 执行所有任务
auto-task run
# 执行指定任务
auto-task run --task "备份代码"
# 使用自定义配置文件
auto-task run --config /path/to/config.json📋 配置说明
全局配置
| 字段 | 类型 | 说明 |
|------|------|------|
| version | string | 配置文件版本 |
| mode | string | 执行模式:series(串行)或 parallel(并行) |
任务配置
| 字段 | 类型 | 必需 | 说明 |
|------|------|------|------|
| name | string | ✅ | 任务名称 |
| command | string | ✅ | 要执行的命令 |
| interval | number | ❌ | 定时间隔(毫秒) |
| schedule | string | ❌ | cron 表达式(未实现) |
| watch | string | ❌ | 监控的文件/目录 |
| debounce | number | ❌ | 防抖延迟(毫秒),默认 1000 |
| cwd | string | ❌ | 工作目录 |
| env | object | ❌ | 环境变量 |
| verbose | boolean | ❌ | 详细输出 |
| stopOnError | boolean | ❌ | 失败时停止,默认 true |
🎯 使用场景
1. 自动备份
{
"name": "备份项目",
"command": "git add . && git commit -m 'auto-backup' && git push",
"interval": 3600000
}2. 文件变化触发测试
{
"name": "运行测试",
"command": "npm test",
"watch": "src/",
"debounce": 2000
}3. 定时清理
{
"name": "清理临时文件",
"command": "rm -rf temp/",
"schedule": "0 0 * * *"
}4. 构建部署流水线
{
"mode": "series",
"tasks": [
{
"name": "安装依赖",
"command": "npm install"
},
{
"name": "运行测试",
"command": "npm test"
},
{
"name": "构建",
"command": "npm run build"
},
{
"name": "部署",
"command": "npm run deploy"
}
]
}🔍 执行模式
串行执行 (series)
任务按顺序执行,前一个任务成功后才执行下一个。
auto-task run --config config-series.json并行执行 (parallel)
所有任务同时执行。
{
"mode": "parallel",
"tasks": [...]
}📊 输出示例
成功
执行任务: 备份代码
命令: git add . && git commit -m 'auto-backup' && git push
✓ 成功 (2450ms)
==================================================
✓ 所有任务成功失败
执行任务: 运行测试
命令: npm test
✗ 失败 (120ms)
stderr: FAIL test/example.test.js
==================================================
✗ 1/2 个任务失败💡 提示
- 使用
interval进行简单的定时任务 - 使用
watch监控文件变化(如代码修改后自动测试) debounce可以防止频繁触发(如保存时)- 定期备份你的配置文件
- 敏感信息使用环境变量(
env字段)
🚧 待实现
- [ ] 完整的 cron 表达式支持
- [ ] 任务依赖
- [ ] 通知功能(邮件、Webhook)
- [ ] 执行历史记录
- [ ] Web UI
🤝 贡献
欢迎提交 Issue 和 PR!
📄 许可证
MIT © 梦心
Made with 🌙 by 梦心
