mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-27 14:46:06 +08:00
添加定时任务进程
This commit is contained in:
parent
12d1884fdd
commit
098f89aa52
37
back/schedule.ts
Normal file
37
back/schedule.ts
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
import schedule from 'node-schedule';
|
||||||
|
import DataStore from 'nedb';
|
||||||
|
import config from './config';
|
||||||
|
import { exec } from 'child_process';
|
||||||
|
import Logger from './loaders/logger';
|
||||||
|
|
||||||
|
const db = new DataStore({ filename: config.cronDbFile, autoload: true });
|
||||||
|
|
||||||
|
const run = async () => {
|
||||||
|
db.find({})
|
||||||
|
.sort({ created: 1 })
|
||||||
|
.exec((err, docs) => {
|
||||||
|
if (err) {
|
||||||
|
Logger.error(err);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (docs && docs.length > 0) {
|
||||||
|
for (let i = 0; i < docs.length; i++) {
|
||||||
|
const task = docs[i];
|
||||||
|
const _schedule = task.schedule && task.schedule.split(' ');
|
||||||
|
if (_schedule && _schedule.length > 5) {
|
||||||
|
schedule.scheduleJob(task.schedule, function () {
|
||||||
|
exec(task.command);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
run();
|
||||||
|
Logger.info(`
|
||||||
|
################################################
|
||||||
|
🛡️ 定时任务schedule启动成功 🛡️
|
||||||
|
################################################
|
||||||
|
`);
|
|
@ -14,17 +14,26 @@ cp -fv $dir_root/docker/front.conf /etc/nginx/conf.d/front.conf
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo -e "======================3. 启动nginx========================\n"
|
echo -e "======================3. 启动nginx========================\n"
|
||||||
nginx -s reload || nginx -c /etc/nginx/nginx.conf
|
nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf
|
||||||
|
echo -e "nginx启动成功...\n"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo -e "======================4. 启动控制面板========================\n"
|
echo -e "======================4. 启动控制面板========================\n"
|
||||||
pm2 start $dir_root/build/app.js -n panel
|
cd $dir_root
|
||||||
|
pm2 restart panel 2>/dev/null || pm2 start npm -n panel -- run panel
|
||||||
echo -e "控制面板启动成功...\n"
|
echo -e "控制面板启动成功...\n"
|
||||||
|
|
||||||
echo -e "\n容器启动成功..."
|
echo -e "======================5. 启动定时任务========================\n"
|
||||||
|
cd $dir_root
|
||||||
|
pm2 restart schedule 2>/dev/null || pm2 start npm -n schedule -- run schedule
|
||||||
|
echo -e "定时任务启动成功...\n"
|
||||||
|
|
||||||
|
echo -e "############################################################"
|
||||||
|
echo -e "容器启动成功..."
|
||||||
echo -e "\n请先访问5700端口,登录面板成功之后先手动执行一次git_pull命令..."
|
echo -e "\n请先访问5700端口,登录面板成功之后先手动执行一次git_pull命令..."
|
||||||
echo -e "\n如果需要启动挂机程序手动执行docker exec -it qinglong js hangup..."
|
echo -e "\n如果需要启动挂机程序手动执行docker exec -it qinglong js hangup..."
|
||||||
echo -e "\n或者去cron管理搜索hangup手动执行挂机任务..."
|
echo -e "\n或者去cron管理搜索hangup手动执行挂机任务..."
|
||||||
|
echo -e "############################################################"
|
||||||
|
|
||||||
crond -f
|
crond -f
|
||||||
|
|
||||||
|
|
24
package.json
24
package.json
|
@ -5,7 +5,8 @@
|
||||||
"build": "umi build",
|
"build": "umi build",
|
||||||
"build-back": "tsc -p tsconfig.back.json",
|
"build-back": "tsc -p tsconfig.back.json",
|
||||||
"start-back": "nodemon",
|
"start-back": "nodemon",
|
||||||
"pm2": "npm run build-back && node build/app.js",
|
"panel": "npm run build-back && node build/app.js",
|
||||||
|
"schedule": "npm run build-back && node build/schedule.js",
|
||||||
"prepare": "umi generate tmp",
|
"prepare": "umi generate tmp",
|
||||||
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
|
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
|
||||||
"test": "umi-test",
|
"test": "umi-test",
|
||||||
|
@ -34,22 +35,13 @@
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"nedb": "^1.8.0",
|
"nedb": "^1.8.0",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
|
"node-schedule": "^2.0.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"typedi": "^0.8.0",
|
"typedi": "^0.8.0",
|
||||||
"winston": "^3.3.3"
|
"winston": "^3.3.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"umi": "^3.3.9",
|
|
||||||
"umi-request": "^1.3.5",
|
|
||||||
"react-codemirror2": "^7.2.1",
|
|
||||||
"react-diff-viewer": "^3.1.1",
|
|
||||||
"react-dnd": "^14.0.2",
|
|
||||||
"react-dnd-html5-backend": "^14.0.0",
|
|
||||||
"qrcode.react": "^1.0.1",
|
|
||||||
"darkreader": "^4.9.27",
|
|
||||||
"codemirror": "^5.59.4",
|
|
||||||
"@ant-design/pro-layout": "^6.5.0",
|
"@ant-design/pro-layout": "^6.5.0",
|
||||||
"@umijs/plugin-antd": "^0.9.1",
|
|
||||||
"@types/cors": "^2.8.10",
|
"@types/cors": "^2.8.10",
|
||||||
"@types/express": "^4.17.8",
|
"@types/express": "^4.17.8",
|
||||||
"@types/express-jwt": "^6.0.1",
|
"@types/express-jwt": "^6.0.1",
|
||||||
|
@ -60,15 +52,25 @@
|
||||||
"@types/qrcode.react": "^1.0.1",
|
"@types/qrcode.react": "^1.0.1",
|
||||||
"@types/react": "^17.0.0",
|
"@types/react": "^17.0.0",
|
||||||
"@types/react-dom": "^17.0.0",
|
"@types/react-dom": "^17.0.0",
|
||||||
|
"@umijs/plugin-antd": "^0.9.1",
|
||||||
"@umijs/test": "^3.3.9",
|
"@umijs/test": "^3.3.9",
|
||||||
|
"codemirror": "^5.59.4",
|
||||||
"compression-webpack-plugin": "6.1.1",
|
"compression-webpack-plugin": "6.1.1",
|
||||||
|
"darkreader": "^4.9.27",
|
||||||
"lint-staged": "^10.0.7",
|
"lint-staged": "^10.0.7",
|
||||||
"nodemon": "^2.0.4",
|
"nodemon": "^2.0.4",
|
||||||
"prettier": "^2.2.0",
|
"prettier": "^2.2.0",
|
||||||
|
"qrcode.react": "^1.0.1",
|
||||||
"react": "17.x",
|
"react": "17.x",
|
||||||
|
"react-codemirror2": "^7.2.1",
|
||||||
|
"react-diff-viewer": "^3.1.1",
|
||||||
|
"react-dnd": "^14.0.2",
|
||||||
|
"react-dnd-html5-backend": "^14.0.0",
|
||||||
"react-dom": "17.x",
|
"react-dom": "17.x",
|
||||||
"ts-node": "^9.0.0",
|
"ts-node": "^9.0.0",
|
||||||
"typescript": "^4.1.2",
|
"typescript": "^4.1.2",
|
||||||
|
"umi": "^3.3.9",
|
||||||
|
"umi-request": "^1.3.5",
|
||||||
"webpack": "^5.28.0",
|
"webpack": "^5.28.0",
|
||||||
"yorkie": "^2.0.0"
|
"yorkie": "^2.0.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,10 @@ run_normal () {
|
||||||
import_config_and_check
|
import_config_and_check
|
||||||
define_program "$p1"
|
define_program "$p1"
|
||||||
combine_all
|
combine_all
|
||||||
|
if [[ $AutoHelpOther == true ]] && [[ $(ls $dir_code) ]]; then
|
||||||
|
local latest_log=$(ls -r $dir_code | head -1)
|
||||||
|
. $dir_code/$latest_log
|
||||||
|
fi
|
||||||
[[ $# -eq 1 ]] && random_delay
|
[[ $# -eq 1 ]] && random_delay
|
||||||
log_time=$(date "+%Y-%m-%d-%H-%M-%S")
|
log_time=$(date "+%Y-%m-%d-%H-%M-%S")
|
||||||
log_path="$dir_log/$p1/$log_time.log"
|
log_path="$dir_log/$p1/$log_time.log"
|
||||||
|
|
|
@ -281,7 +281,7 @@ rebuild_qinglong() {
|
||||||
echo -e "重新编译青龙完成...\n"
|
echo -e "重新编译青龙完成...\n"
|
||||||
|
|
||||||
echo -e "重启青龙...\n"
|
echo -e "重启青龙...\n"
|
||||||
pm2 restart panel 2>/dev/null || pm2 start $dir_root/build/app.js -n panel
|
pm2 restart panel || pm2 start npm -n panel -- run panel
|
||||||
nginx -s reload
|
nginx -s reload
|
||||||
echo -e "重启青龙完成...\n"
|
echo -e "重启青龙完成...\n"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue
Block a user