mirror of
https://github.com/whyour/qinglong.git
synced 2026-08-13 12:23:29 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c32a53c40b | ||
|
|
8ae7a85bf8 | ||
|
|
a56f2393a4 | ||
|
|
1124040eeb | ||
|
|
f043aa62e4 | ||
|
|
d64dc64df7 |
+1
-1
@@ -130,7 +130,7 @@ export default (app: Router) => {
|
|||||||
originFilename: Joi.string().optional().allow(''),
|
originFilename: Joi.string().optional().allow(''),
|
||||||
directory: Joi.string().optional().allow(''),
|
directory: Joi.string().optional().allow(''),
|
||||||
file: Joi.string().optional().allow(''),
|
file: Joi.string().optional().allow(''),
|
||||||
}).unknown(true),
|
}),
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -397,6 +397,21 @@ export function psTree(pid: number): Promise<number[]> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isPidRunning(pid: number): boolean {
|
||||||
|
// Validate PID: must be a positive integer
|
||||||
|
if (pid == null || pid <= 0 || !Number.isInteger(pid)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Signal 0 doesn't kill the process, just checks if it exists
|
||||||
|
process.kill(pid, 0);
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function killTask(pid: number) {
|
export async function killTask(pid: number) {
|
||||||
const pids = await psTree(pid);
|
const pids = await psTree(pid);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { AuthDataType, SystemModel } from '../data/system';
|
|||||||
import SystemService from '../services/system';
|
import SystemService from '../services/system';
|
||||||
import UserService from '../services/user';
|
import UserService from '../services/user';
|
||||||
import { writeFile, readFile } from 'fs/promises';
|
import { writeFile, readFile } from 'fs/promises';
|
||||||
import { createRandomString, fileExist, safeJSONParse } from '../config/util';
|
import { createRandomString, fileExist, safeJSONParse, isPidRunning } from '../config/util';
|
||||||
import OpenService from '../services/open';
|
import OpenService from '../services/open';
|
||||||
import { shareStore } from '../shared/store';
|
import { shareStore } from '../shared/store';
|
||||||
import Logger from './logger';
|
import Logger from './logger';
|
||||||
@@ -132,7 +132,32 @@ export default async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 初始化更新所有任务状态为空闲
|
// 初始化更新所有任务状态为空闲
|
||||||
await CrontabModel.update({ status: CrontabStatus.idle }, { where: {} });
|
// 但保留仍在运行的任务的状态
|
||||||
|
const allCrons = await CrontabModel.findAll({
|
||||||
|
attributes: ['id', 'pid'],
|
||||||
|
raw: true,
|
||||||
|
});
|
||||||
|
const idsToReset: number[] = [];
|
||||||
|
|
||||||
|
for (const cron of allCrons) {
|
||||||
|
// 如果任务有 PID 且进程仍在运行,则保持其状态
|
||||||
|
if (cron.pid != null && isPidRunning(cron.pid)) {
|
||||||
|
// 保留当前状态(running 或 queued)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 收集需要重置的任务 ID
|
||||||
|
if (cron.id) {
|
||||||
|
idsToReset.push(cron.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量更新所有需要重置的任务
|
||||||
|
if (idsToReset.length > 0) {
|
||||||
|
await CrontabModel.update(
|
||||||
|
{ status: CrontabStatus.idle, pid: undefined },
|
||||||
|
{ where: { id: { [Op.in]: idsToReset } } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化时执行一次所有的 ql repo 任务
|
// 初始化时执行一次所有的 ql repo 任务
|
||||||
CrontabModel.findAll({
|
CrontabModel.findAll({
|
||||||
|
|||||||
+4
-20
@@ -482,13 +482,9 @@ function tgBotNotify(text, desp) {
|
|||||||
timeout,
|
timeout,
|
||||||
};
|
};
|
||||||
if (TG_PROXY_HOST && TG_PROXY_PORT) {
|
if (TG_PROXY_HOST && TG_PROXY_PORT) {
|
||||||
let proxyHost = TG_PROXY_HOST;
|
|
||||||
if (TG_PROXY_AUTH && !TG_PROXY_HOST.includes('@')) {
|
|
||||||
proxyHost = `${TG_PROXY_AUTH}@${TG_PROXY_HOST}`;
|
|
||||||
}
|
|
||||||
let agent;
|
let agent;
|
||||||
agent = new ProxyAgent({
|
agent = new ProxyAgent({
|
||||||
uri: `http://${proxyHost}:${TG_PROXY_PORT}`,
|
uri: `http://${TG_PROXY_AUTH}${TG_PROXY_HOST}:${TG_PROXY_PORT}`,
|
||||||
});
|
});
|
||||||
options.dispatcher = agent;
|
options.dispatcher = agent;
|
||||||
}
|
}
|
||||||
@@ -996,10 +992,7 @@ function fsBotNotify(text, desp) {
|
|||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const { FSKEY, FSSECRET } = push_config;
|
const { FSKEY, FSSECRET } = push_config;
|
||||||
if (FSKEY) {
|
if (FSKEY) {
|
||||||
const body = {
|
const body = { msg_type: 'text', content: { text: `${text}\n\n${desp}` } };
|
||||||
msg_type: 'text',
|
|
||||||
content: { text: `${text}\n\n${desp}` },
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add signature if secret is provided
|
// Add signature if secret is provided
|
||||||
// Note: Feishu's signature algorithm uses timestamp+"\n"+secret as the HMAC key
|
// Note: Feishu's signature algorithm uses timestamp+"\n"+secret as the HMAC key
|
||||||
@@ -1285,15 +1278,7 @@ function ntfyNotify(text, desp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const {
|
const { NTFY_URL, NTFY_TOPIC, NTFY_PRIORITY, NTFY_TOKEN, NTFY_USERNAME, NTFY_PASSWORD, NTFY_ACTIONS } = push_config;
|
||||||
NTFY_URL,
|
|
||||||
NTFY_TOPIC,
|
|
||||||
NTFY_PRIORITY,
|
|
||||||
NTFY_TOKEN,
|
|
||||||
NTFY_USERNAME,
|
|
||||||
NTFY_PASSWORD,
|
|
||||||
NTFY_ACTIONS,
|
|
||||||
} = push_config;
|
|
||||||
if (NTFY_TOPIC) {
|
if (NTFY_TOPIC) {
|
||||||
const options = {
|
const options = {
|
||||||
url: `${NTFY_URL || 'https://ntfy.sh'}/${NTFY_TOPIC}`,
|
url: `${NTFY_URL || 'https://ntfy.sh'}/${NTFY_TOPIC}`,
|
||||||
@@ -1308,8 +1293,7 @@ function ntfyNotify(text, desp) {
|
|||||||
if (NTFY_TOKEN) {
|
if (NTFY_TOKEN) {
|
||||||
options.headers['Authorization'] = `Bearer ${NTFY_TOKEN}`;
|
options.headers['Authorization'] = `Bearer ${NTFY_TOKEN}`;
|
||||||
} else if (NTFY_USERNAME && NTFY_PASSWORD) {
|
} else if (NTFY_USERNAME && NTFY_PASSWORD) {
|
||||||
options.headers['Authorization'] =
|
options.headers['Authorization'] = `Basic ${Buffer.from(`${NTFY_USERNAME}:${NTFY_PASSWORD}`).toString('base64')}`;
|
||||||
`Basic ${Buffer.from(`${NTFY_USERNAME}:${NTFY_PASSWORD}`).toString('base64')}`;
|
|
||||||
}
|
}
|
||||||
if (NTFY_ACTIONS) {
|
if (NTFY_ACTIONS) {
|
||||||
options.headers['Actions'] = encodeRFC2047(NTFY_ACTIONS);
|
options.headers['Actions'] = encodeRFC2047(NTFY_ACTIONS);
|
||||||
|
|||||||
Reference in New Issue
Block a user