8 个版本 (1 个稳定版)
1.0.0 | 2023年10月16日 |
---|---|
0.6.0 | 2023年10月11日 |
0.5.1 | 2023年10月5日 |
0.5.0 | 2021年5月29日 |
0.1.0 | 2020年7月19日 |
#2113 in 命令行工具
60 每月下载量
65KB
2K SLoC
runtasktic
Runtasktic 是一个 出色的 命令行任务管理工具,用于执行常规长序列或并行任务。
我们经常需要按预定顺序重复执行多个任务。其中一些任务可能需要花费时间,我们希望在它们结束时收到通知。这就是这个项目存在的原因。
如何在 YAML 文件中描述您的任务,通过 runtasktic 在前台或后台执行所有任务。配置通知系统,并在每个任务结束时或所有任务完成后收到通知。目前仅支持 Slack,需要更多功能?请提交功能请求或拉取请求。
何时需要 runtasktic ?
- 当您有一份冗长的重复运行的任务列表时
- 当您需要在长时间任务完成后收到通知时
- 当您需要一个 nohup 的替代品时
- 当您需要一个 crontab 的替代品时
如何安装 runtasktic ?
您可以通过命令行或从 GitHub 下载预构建版本来安装 runtasktic。
mkdir ~/bin
curl -sSL https://github.com/Joxit/runtasktic/releases/download/$(curl -sSL https://api.github.com/repos/Joxit/runtasktic/releases/latest | jq -r '.tag_name')/runtasktic-linux-x86_64 > ~/bin/runtasktic
chmod +x ~/bin/runtasktic
如果您是 Rust 用户,可以使用 cargo 安装 runtasktic。
cargo install runtasktic
如果您已安装 runtasktic,您可以使用命令行更新它。
runtasktic update
CLI
Command-line task management tool for execution of regular long sequential or parallel tasks.
Usage: runtasktic <COMMAND>
Commands:
run Run all tasks from your configuration in background or foreground
dot Export the configuration to a graph (needs graphviz/dot)
exec Execute a single command with notification in background or foreground
completion Generate completion script for your shell
update Self update of the binary
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
运行:配置文件中的所有任务
Run all tasks from your configuration in background or foreground.
Set the notification, messages, output files, concurency, working directory and many more options in your configuration.
Usage: runtasktic run [OPTIONS] [CONFIG]...
Arguments:
[CONFIG]...
Configurations path (YAML)
Options:
-s, --start <STARTS>
Override the starting task if the job had already been started before. When using many configuration files, start states must be in the first configuration file. Can be many task ids with comma separated values
-b, --background
Run the task in background
--cron <CRON>
Schedule your tasks using cron expression
-h, --help
Print help (see a summary with '-h')
执行:简单的命令,就像 nohup 一样,并带有通知
Execute a single command with notification in background or foreground.
Inherit the notification from a configuration file and set your default one in your home: `~/.runtasktic.yml` or `~/.runtasktic.yaml`.
Usage: runtasktic exec [OPTIONS] [COMMAND]...
Arguments:
[COMMAND]...
Command to execute
Options:
-c, --config <CONFIG>
Configuration path (YAML). Will use config file located `~/.runtasktic.yml` or `~/.runtasktic.yaml` by default. If you want no config file execusion, use `--config -`
-t, --task <TASK>
Run a single task from the configuration file
-b, --background
Exec the command in background
--cron <CRON>
Schedule your tasks using cron expression
-h, --help
Print help (see a summary with '-h')
点:使用 graphviz 创建配置文件的图
Export the configuration to a graph (needs graphviz/dot)
Usage: runtasktic dot <CONFIG> <IMAGE>
Arguments:
<CONFIG> Path of the configuration file to visualize
<IMAGE> Path for the image. `dot` command is required
Options:
-h, --help Print help
示例来自 tests/resources/concurrency.yml,由 dot 生成的图。
完成:为您 shell 生成完成脚本
Generate completion script for your shell
Usage: runtasktic completion <COMMAND>
Commands:
bash Generates a .bash completion file for the Bourne Again SHell (BASH). Save the output in `/etc/bash_completion.d/runtasktic` or `~/.local/share/bash-completion/completions/runtasktic`
fish Generates a .fish completion file for the Friendly Interactive SHell (fish)
zsh Generates a completion file for the Z SHell (ZSH)
elvish Generates a completion file for Elvish
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
更新:更新二进制文件
Self update of the binary
Usage: runtasktic update
Options:
-h, --help Print help
配置
tasks:
a: # The id of the task
commands: # Commands to execute, they must exist with a 0 exit code
- echo Begin a
- sleep 0.5
- echo End a
on_failure: exit # `continue` or `exit` when the tasks ends with a non 0 exit code
b:
commands:
- echo Begin b
- sleep 0.25
- echo End b
depends_on: [a] # This task will be executed after a.
notification:
slack: # send notification to slack
url: https://hooks.slack.com/services/XXXXX/XXXXX/XXXXX # The slack server url
channel: '#channel' # channel to send message
emoji: ':rocket:' # emoji to use (optional)
username: runtasktic # the username to use, default is runtasktic.
print:
output: stderr # print notification on `stdout`, `stedrr`, `none` or `/custom/path`
when: always # `always`, `task-end`, `end` or `never` when should I send notification
messages:
task_end: Task {task.id} ended with status code {task.status_code} # Availables templates are {task.id}, {task.short_cmd}, {task.full_cmd}, {task.status_code}, {hostname}, {env.*} for environment variables
all_task_end: All tasks ended. Got {resume.success} success and {resume.failures} failure. # Availables templates are {resulme.success}, {resume.failures}, {hostname}, {env.*} for environment variables
task_failed: Tasks ended prematurely. Got {resume.success} success and {resume.failures} failure. Contains one critical failure. # Availables templates are {resulme.success}, {resume.failures}, {hostname}, {env.*} for environment variables. Triggered when `on_failure: exit` is used.
concurrency: 2 # how many task can run simultaneously
working_dir: /custom/directory # Where is the workind directory, default is where your are using runtasktic
stdout: none # `none`, `/custom/path` where should I save standard logs
stderr: /var/log/runtasktic.err # `none`, `/custom/path` where should I save error logs
on_failure: continue # `continue` or `exit` default behaviour when a task fail, default is `continue`
配置示例
依赖
~9–21MB
~334K SLoC