From 931f02ef8ec4ede5a40745e00bc70c757a81eed1 Mon Sep 17 00:00:00 2001 From: whyour Date: Tue, 21 Dec 2021 00:23:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=BB=E5=8A=A1=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E8=84=9A=E6=9C=AC=E5=8F=82=E6=95=B0=EF=BC=8Ctask?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E8=84=9A=E6=9C=AC=E6=94=AF=E6=8C=81=E6=9B=B4?= =?UTF-8?q?=E5=A4=9A=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/commands/update.ts | 13 +++++++++++++ cli/index.ts | 12 +++++++++++- shell/task.sh | 27 ++++++++++++++++++++------- src/pages/crontab/index.tsx | 6 +++++- 4 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 cli/commands/update.ts diff --git a/cli/commands/update.ts b/cli/commands/update.ts new file mode 100644 index 00000000..f3da511a --- /dev/null +++ b/cli/commands/update.ts @@ -0,0 +1,13 @@ +import { CommandModule } from 'yargs'; +export const updateCommand: CommandModule = { + command: 'update', + describe: 'Update and restart qinglong', + builder: (yargs) => { + return yargs.option('repositority', { + type: 'string', + alias: 'r', + describe: `Specify the release warehouse address of the package`, + }); + }, + handler: async (argv) => {}, +}; diff --git a/cli/index.ts b/cli/index.ts index 8c7bb817..ce7ca0d1 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -1,3 +1,13 @@ import * as yargs from 'yargs'; +import { green, red } from 'chalk'; +import { updateCommand } from './commands/update'; -yargs.help('h').alias('h', 'help').help().argv; +yargs + .usage('Usage: ql [command] ') + .command(updateCommand) + .fail((err) => { + console.error(`${red(err)}`); + }) + .alias('h', 'help') + .showHelp() + .recommendCommands().argv; diff --git a/shell/task.sh b/shell/task.sh index 708133e7..093c0198 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -264,13 +264,18 @@ run_designated() { ## 运行其他命令 run_else() { - local log_time=$(date "+%Y-%m-%d-%H-%M-%S") - local log_dir_tmp="${1##*/}" - local log_dir="$dir_log/${log_dir_tmp%%.*}" + local file_param="$1" + define_program "$file_param" + log_time=$(date "+%Y-%m-%d-%H-%M-%S") + log_dir_tmp="${file_param##*/}" + log_dir_tmp_path="${file_param%%/*}" + log_dir_tmp_path="${log_dir_tmp_path##*/}" + [[ $log_dir_tmp_path ]] && log_dir_tmp="${log_dir_tmp_path}_${log_dir_tmp}" + log_dir="$dir_log/${log_dir_tmp%%.*}" log_path="$log_dir/$log_time.log" cmd="&>> $log_path" [[ "$show_log" == "true" ]] && cmd="" - make_dir "$log_dir" + make_dir $log_dir local begin_time=$(date '+%Y-%m-%d %H:%M:%S') local begin_timestamp=$(date "+%s" -d "$begin_time") @@ -278,13 +283,21 @@ run_else() { eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd [[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd - local id=$(cat $list_crontab_user | grep -E "$cmd_task $first_param" | perl -pe "s|.*ID=(.*) $cmd_task $first_param\.*|\1|" | head -1 | awk -F " " '{print $1}') + local id=$(cat $list_crontab_user | grep -E "$cmd_task $@" | perl -pe "s|.*ID=(.*) $cmd_task $@\.*|\1|" | head -1 | awk -F " " '{print $1}') [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" "$begin_timestamp" eval . $file_task_before "$@" $cmd - eval timeout -k 10s $command_timeout_time "$@" $cmd + cd $dir_scripts + local relative_path="${file_param%/*}" + if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then + cd ${relative_path} + file_param=${file_param/$relative_path\//} + fi - eval . $file_task_after "$@" $cmd + shift + eval timeout -k 10s $command_timeout_time $which_program "$file_param" "$@" $cmd + + eval . $file_task_after "$file_param" "$@" $cmd local end_time=$(date '+%Y-%m-%d %H:%M:%S') local end_timestamp=$(date "+%s" -d "$end_time") local diff_time=$(( $end_timestamp - $begin_timestamp )) diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index 8f44436d..63092a5e 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -335,8 +335,12 @@ const Crontab = ({ headerStyle, isPhone }: any) => { const [tableScrollHeight, setTableScrollHeight] = useState(); const goToScriptManager = (record: any) => { - const cmd = record.command.split(' '); + const cmd = record.command.split(' ') as string[]; if (cmd[0] === 'task') { + if (cmd[1].startsWith('/ql/scripts')) { + cmd[1] = cmd[1].replace('/ql/scripts/', ''); + } + let [p, s] = cmd[1].split('/'); if (!s) { s = p;