任务增加关联订阅

This commit is contained in:
whyour
2023-02-13 23:50:01 +08:00
parent 1f7f2c8971
commit 7bce5c4f6a
9 changed files with 31 additions and 22 deletions
+2
View File
@@ -160,6 +160,7 @@ export default (app: Router) => {
schedule: Joi.string().required(),
name: Joi.string().optional(),
labels: Joi.array().optional(),
sub_id: Joi.number().optional().allow(null),
}),
}),
async (req: Request, res: Response, next: NextFunction) => {
@@ -316,6 +317,7 @@ export default (app: Router) => {
command: Joi.string().required(),
schedule: Joi.string().required(),
name: Joi.string().optional().allow(null),
sub_id: Joi.number().optional().allow(null),
id: Joi.number().required(),
}),
}),
+1 -1
View File
@@ -17,7 +17,7 @@ export function formatUrl(doc: Subscription) {
}
export function formatCommand(doc: Subscription, url?: string) {
let command = 'ql ';
let command = `SUB_ID=${doc.id} ql `;
let _url = url || formatUrl(doc).url;
const {
type,
+3
View File
@@ -17,6 +17,7 @@ export class Crontab {
labels?: string[];
last_running_time?: number;
last_execution_time?: number;
sub_id?: number;
constructor(options: Crontab) {
this.name = options.name;
@@ -37,6 +38,7 @@ export class Crontab {
this.labels = options.labels || [];
this.last_running_time = options.last_running_time || 0;
this.last_execution_time = options.last_execution_time || 0;
this.sub_id = options.sub_id;
}
}
@@ -72,4 +74,5 @@ export const CrontabModel = sequelize.define<CronInstance>('Crontab', {
labels: DataTypes.JSON,
last_running_time: DataTypes.NUMBER,
last_execution_time: DataTypes.NUMBER,
sub_id: { type: DataTypes.NUMBER, allowNull: true },
});
+3
View File
@@ -46,6 +46,9 @@ export default async () => {
'alter table Subscriptions add column autoDelCron NUMBER',
);
} catch (error) {}
try {
await sequelize.query('alter table Crontabs add column sub_id NUMBER');
} catch (error) {}
// 2.10-2.11 升级
const cronDbFile = path.join(config.rootPath, 'db/crontab.db');
+4 -4
View File
@@ -63,8 +63,8 @@ export default class ScheduleService {
});
cp.stderr.on('data', async (data) => {
this.logger.error(
'执行任务 %s 失败,时间:%s, 错误信息:%j',
this.logger.info(
'[执行任务失败] %s,时间:%s, 错误信息:%j',
command,
new Date().toLocaleString(),
data.toString(),
@@ -74,7 +74,7 @@ export default class ScheduleService {
cp.on('error', async (err) => {
this.logger.error(
'创建任务 %s 失败,时间:%s, 错误信息:%j',
'[创建任务失败] %s,时间:%s, 错误信息:%j',
command,
new Date().toLocaleString(),
err,
@@ -84,7 +84,7 @@ export default class ScheduleService {
cp.on('exit', async (code, signal) => {
this.logger.info(
`任务 ${command} 进程id: ${cp.pid} 退出,退出码 ${code}`,
`[任务退出] ${command} 进程id: ${cp.pid},退出码 ${code}`,
);
});
-1
View File
@@ -110,7 +110,6 @@ export default class SshKeyService {
(doc.pull_option as any).private_key,
);
const config = this.generateSingleSshConfig(alias, host, proxy);
console.log(config);
result.push(config);
}
}