Skip to content

Commit

Permalink
task 命令支持给脚本传参,使用 -- 分割,后面的参数都会传给脚本
Browse files Browse the repository at this point in the history
例如 task x.js -n whyour,脚本就能接收到参数 -n whyour
  • Loading branch information
whyour committed Oct 14, 2023
1 parent 5055045 commit 9fb9b3d
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 80 deletions.
69 changes: 38 additions & 31 deletions README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Timed task management platform supporting Python3, JavaScript, Shell, Typescript
- Support cell phone operation

## Version

### docker

The `latest` image is built on `alpine` and the `debian` image is built on `debian-slim`. If you need to use a dependency that is not supported by `alpine`, it is recommended that you use the `debian` image.
Expand Down Expand Up @@ -118,9 +119,30 @@ export QL_DATA_DIR=""
qinglong
```

## Use
## Built-in commands

1. task

```bash
# Execute in sequence, if a random delay is set, it will be randomly delayed by a certain number of seconds
task <file_path>
# Execute in sequence, regardless of whether a random delay is set, all run immediately,
# and the foreground will output the day, while recorded in the log file
task <file_path> now
# Concurrent execution, regardless of whether a random delay is set, are run immediately,
# the foreground does not generate the day, directly recorded in the log file, and can be specified account execution
task <file_path> conc <env_name> <account_number>(Optional)
# Specify the account to execute and run immediately regardless of whether a random delay is set
task <file_path> desi <env_name> <account_number>
# Set task timeout
task -m <max_time> <file_path>
# Print task log in real time, no need to carry this parameter when creating timed tasks
task -l <file_path>
# Use -- to split, -- followed by a parameter that is passed to the script, as in the following example, the script receives the parameter -u whyour -p password
task <file_path> -- -u whyour -p password
```

1. built-in commands
1. ql

```bash
# Update and restart Green Dragon
Expand All @@ -141,36 +163,21 @@ ql check
ql resetlet
# Disable two-step login
ql resettfa

# Execute in sequence, if a random delay is set, it will be randomly delayed by a certain number of seconds
task <file_path>
# Execute in sequence, regardless of whether a random delay is set, all run immediately,
# and the foreground will output the day, while recorded in the log file
task <file_path> now
# Concurrent execution, regardless of whether a random delay is set, are run immediately,
# the foreground does not generate the day, directly recorded in the log file, and can be specified account execution
task <file_path> conc <env_name> <account_number>(Optional)
# Specify the account to execute and run immediately regardless of whether a random delay is set
task <file_path> desi <env_name> <account_number>
# Set task timeout
task -m <max_time> <file_path>
# Print task log in real time, no need to carry this parameter when creating timed tasks
task -l <file_path>
```

2. parameter description
1. parameter description

* file_url: Script address
* repo_url: Repository address
* whitelist: The whitelist when pulling the repository, i.e., the string contained in the path of the script to be pulled
* blacklist: Blacklisting when pulling repositories, i.e. strings that are not included in the path of the script to be pulled
* dependence: Pulling the dependencies needed for the repository will be copied directly from the repository to the repository directory under scripts, regardless of the blacklist
* branch: Pull the branch of the repository
* days: Number of days of logs to be kept
* file_path: File path for task execution
* env_name: The name of the environment variable that needs to be concurrent or specified at the time of task execution
* account_number: Specify the account number of an environment variable to be executed when the task is executed
* max_time: Timeout, suffix "s" for seconds (default), "m" for minutes, "h" for hours, "d" for days
- file_url: Script address
- repo_url: Repository address
- whitelist: The whitelist when pulling the repository, i.e., the string contained in the path of the script to be pulled
- blacklist: Blacklisting when pulling repositories, i.e. strings that are not included in the path of the script to be pulled
- dependence: Pulling the dependencies needed for the repository will be copied directly from the repository to the repository directory under scripts, regardless of the blacklist
- branch: Pull the branch of the repository
- days: Number of days of logs to be kept
- file_path: File path for task execution
- env_name: The name of the environment variable that needs to be concurrent or specified at the time of task execution
- account_number: Specify the account number of an environment variable to be executed when the task is executed
- max_time: Timeout, suffix "s" for seconds (default), "m" for minutes, "h" for hours, "d" for days

## Development

Expand All @@ -184,7 +191,7 @@ $ pnpm install
$ pnpm start
```

Open your browser and visit http://127.0.0.1:5700
Open your browser and visit <http://127.0.0.1:5700>

## Links

Expand All @@ -202,4 +209,4 @@ The Green Dragon, also known as the Canglong, is one of the four elephants and o

In the Book of the Later Han Dynasty (後漢書-律曆志下), it is written: "The sun is in the sky, a cold and a summer, the four seasons are ready, all things are changed, the regency moves, and the green dragon moves to the star, which is called the year. (The Year of the Star)

Among the [twenty-eight Chinese constellations](https://zh.wikipedia.org/wiki/%E4%BA%8C%E5%8D%81%E5%85%AB%E5%AE%BF), the Green Dragon is the generic name for the seven eastern constellations (Horn, Hyper, Diao, Fang, Heart, Tail and Minchi). It is known in Taoism as "Mengzhang" and in different Taoist scriptures as "Dijun", "Shengjian", "Shenjian" and He is also known in different Daoist scriptures as "Dijun", "Shengjun", "Shenjun" and "Ghost Catcher"[1], and is the guardian deity of Daoism, together with the White Tiger Supervisor of Soldiers.
Among the [twenty-eight Chinese constellations](https://zh.wikipedia.org/wiki/%E4%BA%8C%E5%8D%81%E5%85%AB%E5%AE%BF), the Green Dragon is the generic name for the seven eastern constellations (Horn, Hyper, Diao, Fang, Heart, Tail and Minchi). It is known in Taoism as "Mengzhang" and in different Taoist scriptures as "Dijun", "Shengjian", "Shenjian" and He is also known in different Daoist scriptures as "Dijun", "Shengjun", "Shenjun" and "Ghost Catcher"[1], and is the guardian deity of Daoism, together with the White Tiger Supervisor of Soldiers.
76 changes: 41 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,11 @@ export QL_DATA_DIR=""
qinglong
```

## 使用
## 内置命令

1. 内置命令
1. task

```bash
# 更新并重启青龙
ql update
# 运行自定义脚本extra.sh
ql extra
# 添加单个脚本文件
ql raw <file_url>
# 添加单个仓库的指定脚本
ql repo <repo_url> <whitelist> <blacklist> <dependence> <branch> <extensions>
# 删除旧日志
ql rmlog <days>
# 启动tg-bot
ql bot
# 检测青龙环境并修复
ql check
# 重置登录错误次数
ql resetlet
# 禁用两步登录
ql resettfa

# 依次执行,如果设置了随机延迟,将随机延迟一定秒数
task <file_path>
# 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日,同时记录在日志文件中
Expand All @@ -156,22 +137,47 @@ task <file_path> desi <env_name> <account_number>
task -m <max_time> <file_path>
# 实时打印任务日志,创建定时任务时,不用携带此参数
task -l <file_path>
# 使用 -- 分割,-- 后面的参数会传给脚本,下面的例子,脚本就可接收到参数 -u whyour -p password
task <file_path> -- -u whyour -p password
```

1. ql

```bash
# 更新并重启青龙
ql update
# 运行自定义脚本extra.sh
ql extra
# 添加单个脚本文件
ql raw <file_url>
# 添加单个仓库的指定脚本
ql repo <repo_url> <whitelist> <blacklist> <dependence> <branch> <extensions>
# 删除旧日志
ql rmlog <days>
# 启动tg-bot
ql bot
# 检测青龙环境并修复
ql check
# 重置登录错误次数
ql resetlet
# 禁用两步登录
ql resettfa
```

2. 参数说明

* file_url: 脚本地址
* repo_url: 仓库地址
* whitelist: 拉取仓库时的白名单,即就是需要拉取的脚本的路径包含的字符串,多个竖线分割
* blacklist: 拉取仓库时的黑名单,即就是需要拉取的脚本的路径不包含的字符串,多个竖线分割
* dependence: 拉取仓库需要的依赖文件,会直接从仓库拷贝到scripts下的仓库目录,不受黑名单影响,多个竖线分割
* extensions: 拉取仓库的文件后缀,多个竖线分割
* branch: 拉取仓库的分支
* days: 需要保留的日志的天数
* file_path: 任务执行时的文件路径
* env_name: 任务执行时需要并发或者指定时的环境变量名称
* account_number: 任务执行时指定某个环境变量需要执行的账号序号
* max_time: 超时时间,后缀"s"代表秒(默认值), "m"代表分, "h"代表小时, "d"代表天
1. 参数说明

- file_url: 脚本地址
- repo_url: 仓库地址
- whitelist: 拉取仓库时的白名单,即就是需要拉取的脚本的路径包含的字符串,多个竖线分割
- blacklist: 拉取仓库时的黑名单,即就是需要拉取的脚本的路径不包含的字符串,多个竖线分割
- dependence: 拉取仓库需要的依赖文件,会直接从仓库拷贝到scripts下的仓库目录,不受黑名单影响,多个竖线分割
- extensions: 拉取仓库的文件后缀,多个竖线分割
- branch: 拉取仓库的分支
- days: 需要保留的日志的天数
- file_path: 任务执行时的文件路径
- env_name: 任务执行时需要并发或者指定时的环境变量名称
- account_number: 任务执行时指定某个环境变量需要执行的账号序号
- max_time: 超时时间,后缀"s"代表秒(默认值), "m"代表分, "h"代表小时, "d"代表天

## 开发

Expand Down
16 changes: 8 additions & 8 deletions shell/otask.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ run_normal() {
file_param=${file_param/$relative_path\//}
fi

$timeoutCmd $which_program $file_param
$timeoutCmd $which_program $file_param "${script_params[@]}"
}

## 并发执行时,设定的 RandomDelay 不会生效,即所有任务立即执行
Expand Down Expand Up @@ -147,7 +147,7 @@ run_concurrent() {
for i in "${!array[@]}"; do
export "${env_param}=${array[i]}"
single_log_path="$dir_log/$log_dir/${single_log_time}_$((i + 1)).log"
eval $timeoutCmd $which_program $file_param &>$single_log_path &
eval $timeoutCmd $which_program $file_param "${script_params[@]}" &>$single_log_path &
done

wait
Expand Down Expand Up @@ -190,7 +190,7 @@ run_designated() {
cd ${relative_path}
file_param=${file_param/$relative_path\//}
fi
$timeoutCmd $which_program $file_param
$timeoutCmd $which_program $file_param "${script_params[@]}"
}

## 运行其他命令
Expand Down Expand Up @@ -241,8 +241,8 @@ main() {
fi
}

handle_task_start "$@"
run_task_before "$@"
main "$@"
run_task_after "$@"
handle_task_end "$@"
handle_task_start "${task_shell_params[@]}"
run_task_before "${task_shell_params[@]}"
main "${task_shell_params[@]}"
run_task_after "${task_shell_params[@]}"
handle_task_end "${task_shell_params[@]}"
19 changes: 17 additions & 2 deletions shell/task.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ format_params() {
fi
fi
# params=$(echo "$@" | sed -E 's/([^ ])&([^ ])/\1\\\&\2/g')

# 分割 task 内置参数和脚本参数
task_shell_params=()
script_params=()
found_double_dash=false

for arg in "$@"; do
if $found_double_dash; then
script_params+=("$arg")
elif [ "$arg" == "--" ]; then
found_double_dash=true
else
task_shell_params+=("$arg")
fi
done
}

init_begin_time() {
Expand All @@ -119,8 +134,8 @@ if [[ $max_time ]]; then
fi

format_params "$@"
define_program "$@"
handle_log_path "$@"
define_program "${task_shell_params[@]}"
handle_log_path "${task_shell_params[@]}"
init_begin_time

eval . $dir_shell/otask.sh "$cmd"
Expand Down
7 changes: 6 additions & 1 deletion src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,5 +461,10 @@
"运行任务后执行的命令,比如 cp/mv/python3 xxx.py/node xxx.js": "Run commands after executing the task, e.g., cp/mv/python3 xxx.py/node xxx.js",
"请输入运行任务前要执行的命令,不能包含 task 命令": "Please enter the command to run before executing the task, cannot contain task commands",
"请输入运行任务后要执行的命令,不能包含 task 命令": "Please enter the command to run after executing the task, cannot contain task commands",
"不能包含 task 命令": "Cannot contain task commands"
"不能包含 task 命令": "Cannot contain task commands",
"Chronocat Red 服务的连接地址 https://chronocat.vercel.app/install/docker/official/": "Connection address of the Chronocat Red service https://chronocat.vercel.app/install/docker/official/",
"个人:user_id=个人QQ 群则填入group_id=QQ群 多个用英文;隔开同时支持个人和群 如:user_id=xxx;group_id=xxxx;group_id=xxxxx": "Individuals: user_id=individual QQ Groups fill in group_id=QQ Groups more than one with English; separated by the same time to support individuals and groups such as: user_id=xxx;group_id=xxxx;group_id=xxxxx",
"docker安装在持久化config目录下的chronocat.yml文件可找到": "The docker installation can be found in the persistence config directory in the chronocat.yml file",
"请选择": "Please select",
"请输入": "Please input"
}
7 changes: 6 additions & 1 deletion src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,5 +461,10 @@
"运行任务后执行的命令,比如 cp/mv/python3 xxx.py/node xxx.js": "运行任务后执行的命令,比如 cp/mv/python3 xxx.py/node xxx.js",
"请输入运行任务前要执行的命令,不能包含 task 命令": "请输入运行任务前要执行的命令,不能包含 task 命令",
"请输入运行任务后要执行的命令,不能包含 task 命令": "请输入运行任务后要执行的命令,不能包含 task 命令",
"不能包含 task 命令": "不能包含 task 命令"
"不能包含 task 命令": "不能包含 task 命令",
"Chronocat Red 服务的连接地址 https://chronocat.vercel.app/install/docker/official/": "Chronocat Red 服务的连接地址 https://chronocat.vercel.app/install/docker/official/",
"个人:user_id=个人QQ 群则填入group_id=QQ群 多个用英文;隔开同时支持个人和群 如:user_id=xxx;group_id=xxxx;group_id=xxxxx": "个人:user_id=个人QQ 群则填入group_id=QQ群 多个用英文;隔开同时支持个人和群 如:user_id=xxx;group_id=xxxx;group_id=xxxxx",
"docker安装在持久化config目录下的chronocat.yml文件可找到": "docker安装在持久化config目录下的chronocat.yml文件可找到",
"请选择": "请选择",
"请输入": "请输入"
}
4 changes: 2 additions & 2 deletions src/pages/setting/notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const NotificationSetting = ({ data }: any) => {
>
{x.items ? (
<Select
placeholder={x.placeholder || `请选择${x.label}`}
placeholder={x.placeholder || `${intl.get('请选择')} ${x.label}`}
disabled={loading}
>
{x.items.map((y) => (
Expand All @@ -89,7 +89,7 @@ const NotificationSetting = ({ data }: any) => {
<Input.TextArea
disabled={loading}
autoSize={{ minRows: 1, maxRows: 5 }}
placeholder={x.placeholder || `请输入${x.label}`}
placeholder={x.placeholder || `${intl.get('请输入')} ${x.label}`}
/>
)}
</Form.Item>
Expand Down

0 comments on commit 9fb9b3d

Please sign in to comment.