mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
增加自动运行任务时任务状态展示
1. 添加bot远程地址 2. 增加文件后缀配置 3. 增加定时任务页数缓存
This commit is contained in:
parent
424a1e6491
commit
1923ceb5c2
|
@ -225,4 +225,25 @@ export default (app: Router) => {
|
|||
}
|
||||
},
|
||||
);
|
||||
|
||||
route.put(
|
||||
'/crons/status',
|
||||
celebrate({
|
||||
body: Joi.object({
|
||||
ids: Joi.array().items(Joi.string().required()),
|
||||
status: Joi.string().required(),
|
||||
}),
|
||||
}),
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
const logger: Logger = Container.get('logger');
|
||||
try {
|
||||
const cronService = Container.get(CronService);
|
||||
const data = await cronService.status(req.body);
|
||||
return res.send({ code: 200, data });
|
||||
} catch (e) {
|
||||
logger.error('🔥 error: %o', e);
|
||||
return next(e);
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
|
|
@ -83,8 +83,14 @@ export default class CronService {
|
|||
});
|
||||
}
|
||||
|
||||
public async status(_id: string, stopped: boolean) {
|
||||
this.cronDb.update({ _id }, { $set: { stopped, saved: false } });
|
||||
public async status({
|
||||
ids,
|
||||
status,
|
||||
}: {
|
||||
ids: string[];
|
||||
status: CrontabStatus;
|
||||
}) {
|
||||
this.cronDb.update({ _id: { $in: ids } }, { $set: { status } });
|
||||
}
|
||||
|
||||
public async remove(ids: string[]) {
|
||||
|
|
|
@ -10,6 +10,9 @@ AutoDelCron="true"
|
|||
## 在运行 ql repo 命令时,是否自动增加新的本地定时任务
|
||||
AutoAddCron="true"
|
||||
|
||||
## ql repo命令拉取脚本时需要拉取的文件后缀,直接写文件后缀名即可
|
||||
RepoFileExtensions="js py"
|
||||
|
||||
## 由于github仓库拉取较慢,所以会默认添加代理前缀,如不需要请移除
|
||||
GithubProxyUrl="https://ghproxy.com/"
|
||||
|
||||
|
|
26
shell/api.sh
26
shell/api.sh
|
@ -147,3 +147,29 @@ get_user_info() {
|
|||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
update_cron_status() {
|
||||
local ids=$1
|
||||
local status=$2
|
||||
local currentTimeStamp=$(date +%s)
|
||||
local api=$(
|
||||
curl -s "http://localhost:5700/api/crons/status?t=$currentTimeStamp" \
|
||||
-X 'PUT' \
|
||||
-H "Accept: application/json" \
|
||||
-H "Authorization: Bearer $token" \
|
||||
-H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36" \
|
||||
-H "Content-Type: application/json;charset=UTF-8" \
|
||||
-H "Origin: http://localhost:5700" \
|
||||
-H "Referer: http://localhost:5700/crontab" \
|
||||
-H "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7" \
|
||||
--data-raw "{\"ids\":\"[$ids]\",\"status\":\"$status\"}" \
|
||||
--compressed
|
||||
)
|
||||
code=$(echo $api | jq -r .code)
|
||||
message=$(echo $api | jq -r .message)
|
||||
if [[ $code == 200 ]]; then
|
||||
echo -e "成功"
|
||||
else
|
||||
echo -e "失败(${message})"
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
## 导入通用变量与函数
|
||||
dir_shell=/ql/shell
|
||||
. $dir_shell/share.sh
|
||||
url="${github_proxy_url}https://github.com/SuMaiKaDe/bot.git"
|
||||
repo_path="${dir_repo}/dockerbot"
|
||||
|
||||
echo -e "\n1、安装bot依赖...\n"
|
||||
|
@ -10,6 +11,13 @@ apk --no-cache add -f zlib-dev gcc jpeg-dev python3-dev musl-dev freetype-dev
|
|||
echo -e "\nbot依赖安装成功...\n"
|
||||
|
||||
echo -e "2、下载bot所需文件...\n"
|
||||
if [ -d ${repo_path}/.git ]; then
|
||||
git_pull_scripts ${repo_path}
|
||||
else
|
||||
rm -rf ${repo_path}
|
||||
git_clone_scripts ${url} ${repo_path} "main"
|
||||
fi
|
||||
|
||||
cp -rf "$repo_path/jbot" $dir_root
|
||||
if [[ ! -f "$dir_root/config/bot.json" ]]; then
|
||||
cp -f "$repo_path/config/bot.json" "$dir_root/config"
|
||||
|
|
|
@ -62,6 +62,7 @@ import_config() {
|
|||
command_timeout_time=${CommandTimeoutTime:-"1h"}
|
||||
github_proxy_url=${GithubProxyUrl:-""}
|
||||
block_cookie=${TempBlockCookie:-""}
|
||||
file_extensions=${RepoFileExtensions:-"js py"}
|
||||
}
|
||||
|
||||
## 创建目录,$1:目录的绝对路径
|
||||
|
|
|
@ -120,6 +120,10 @@ run_normal() {
|
|||
log_dir="$dir_log/${log_dir_tmp%%.*}"
|
||||
log_path="$log_dir/$log_time.log"
|
||||
make_dir "$log_dir"
|
||||
|
||||
local id=$(cat $list_crontab_user | grep -E "$cmd_task $p1$" | perl -pe "s|.*ID=(.*) $cmd_task $p1$|\1|" | xargs | sed 's/ /","/g')
|
||||
local status="0" ## 0 任务运行中
|
||||
update_cron_status "\"$id\"" $status
|
||||
timeout $command_timeout_time $which_program $p1 2>&1 | tee $log_path
|
||||
}
|
||||
|
||||
|
|
|
@ -357,7 +357,12 @@ gen_list_repo() {
|
|||
rm -f $dir_list_tmp/${repo}*.list >/dev/null 2>&1
|
||||
|
||||
cd ${repo_path}
|
||||
files=$(find . -name "*.js" | sed 's/^..//')
|
||||
|
||||
local cmd="find ."
|
||||
for extension in $file_extensions; do
|
||||
cmd="${cmd} -o -name \"*.${extension}\""
|
||||
done
|
||||
files=$($cmd | sed 's/^..//')
|
||||
if [[ $path ]]; then
|
||||
files=$(echo "$files" | egrep $path)
|
||||
fi
|
||||
|
@ -365,7 +370,7 @@ gen_list_repo() {
|
|||
files=$(echo "$files" | egrep -v $blackword)
|
||||
fi
|
||||
if [[ $dependence ]]; then
|
||||
find . -name "*.js" | sed 's/^..//' | egrep $dependence | xargs -i cp {} $dir_scripts
|
||||
$cmd | sed 's/^..//' | egrep $dependence | xargs -i cp {} $dir_scripts
|
||||
fi
|
||||
for file in ${files}; do
|
||||
filename=$(basename $file)
|
||||
|
|
|
@ -187,6 +187,8 @@ const Crontab = () => {
|
|||
const [isLogModalVisible, setIsLogModalVisible] = useState(false);
|
||||
const [logCron, setLogCron] = useState<any>();
|
||||
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([]);
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const [pageSize, setPageSize] = useState(20);
|
||||
|
||||
const getCrons = () => {
|
||||
setLoading(true);
|
||||
|
@ -233,7 +235,7 @@ const Crontab = () => {
|
|||
if (data.code === 200) {
|
||||
message.success('删除成功');
|
||||
const result = [...value];
|
||||
result.splice(index, 1);
|
||||
result.splice(index + pageSize * (currentPage - 1), 1);
|
||||
setValue(result);
|
||||
} else {
|
||||
message.error(data);
|
||||
|
@ -264,7 +266,7 @@ const Crontab = () => {
|
|||
.then((data: any) => {
|
||||
if (data.code === 200) {
|
||||
const result = [...value];
|
||||
result.splice(index, 1, {
|
||||
result.splice(index + pageSize * (currentPage - 1), 1, {
|
||||
...record,
|
||||
status: CrontabStatus.running,
|
||||
});
|
||||
|
@ -298,7 +300,7 @@ const Crontab = () => {
|
|||
.then((data: any) => {
|
||||
if (data.code === 200) {
|
||||
const result = [...value];
|
||||
result.splice(index, 1, {
|
||||
result.splice(index + pageSize * (currentPage - 1), 1, {
|
||||
...record,
|
||||
pid: null,
|
||||
status: CrontabStatus.idle,
|
||||
|
@ -342,7 +344,7 @@ const Crontab = () => {
|
|||
if (data.code === 200) {
|
||||
const newStatus = record.isDisabled === 1 ? 0 : 1;
|
||||
const result = [...value];
|
||||
result.splice(index, 1, {
|
||||
result.splice(index + pageSize * (currentPage - 1), 1, {
|
||||
...record,
|
||||
isDisabled: newStatus,
|
||||
});
|
||||
|
@ -429,7 +431,7 @@ const Crontab = () => {
|
|||
if (index === -1) {
|
||||
result.push(cron);
|
||||
} else {
|
||||
result.splice(index, 1, {
|
||||
result.splice(index + pageSize * (currentPage - 1), 1, {
|
||||
...cron,
|
||||
});
|
||||
}
|
||||
|
@ -442,7 +444,7 @@ const Crontab = () => {
|
|||
.then((data: any) => {
|
||||
const index = value.findIndex((x) => x._id === cron._id);
|
||||
const result = [...value];
|
||||
result.splice(index, 1, {
|
||||
result.splice(index + pageSize * (currentPage - 1), 1, {
|
||||
...cron,
|
||||
...data.data,
|
||||
});
|
||||
|
@ -511,6 +513,12 @@ const Crontab = () => {
|
|||
});
|
||||
};
|
||||
|
||||
const onPageChange = (page: number, pageSize: number | undefined) => {
|
||||
setCurrentPage(page);
|
||||
setPageSize(pageSize as number);
|
||||
localStorage.setItem('pageSize', pageSize + '');
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (logCron) {
|
||||
localStorage.setItem('logCron', logCron._id);
|
||||
|
@ -532,6 +540,7 @@ const Crontab = () => {
|
|||
setMarginLeft(0);
|
||||
setMarginTop(-72);
|
||||
}
|
||||
setPageSize(parseInt(localStorage.getItem('pageSize') || '20'));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
|
@ -602,6 +611,9 @@ const Crontab = () => {
|
|||
columns={columns}
|
||||
pagination={{
|
||||
hideOnSinglePage: true,
|
||||
current: currentPage,
|
||||
onChange: onPageChange,
|
||||
pageSize: pageSize,
|
||||
showSizeChanger: true,
|
||||
defaultPageSize: 20,
|
||||
showTotal: (total: number, range: number[]) =>
|
||||
|
|
Loading…
Reference in New Issue
Block a user