mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 14:56:07 +08:00
修改订阅执行逻辑
This commit is contained in:
parent
6116aa6d12
commit
b160f914ad
|
@ -18,6 +18,7 @@ interface ScheduleTaskType {
|
|||
}
|
||||
|
||||
export interface TaskCallbacks {
|
||||
onBefore?: (startTime: dayjs.Dayjs) => Promise<void>;
|
||||
onStart?: (
|
||||
cp: ChildProcessWithoutNullStreams,
|
||||
startTime: dayjs.Dayjs,
|
||||
|
@ -45,6 +46,8 @@ export default class ScheduleService {
|
|||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const startTime = dayjs();
|
||||
await callbacks.onBefore?.(startTime);
|
||||
|
||||
const cp = spawn(command, { shell: '/bin/bash' });
|
||||
|
||||
// TODO:
|
||||
|
|
|
@ -192,14 +192,13 @@ export default class SubscriptionService {
|
|||
|
||||
private taskCallbacks(doc: Subscription): TaskCallbacks {
|
||||
return {
|
||||
onStart: async (cp: ChildProcessWithoutNullStreams, startTime) => {
|
||||
onBefore: async (startTime) => {
|
||||
const logTime = startTime.format('YYYY-MM-DD-HH-mm-ss');
|
||||
const logPath = `${doc.alias}/${logTime}.log`;
|
||||
await SubscriptionModel.update(
|
||||
{
|
||||
status: SubscriptionStatus.running,
|
||||
log_path: logPath,
|
||||
pid: cp.pid,
|
||||
},
|
||||
{ where: { id: doc.id } },
|
||||
);
|
||||
|
@ -220,9 +219,17 @@ export default class SubscriptionService {
|
|||
(error.stderr && error.stderr.toString()) || JSON.stringify(error);
|
||||
}
|
||||
if (beforeStr) {
|
||||
fs.appendFileSync(absolutePath, `${beforeStr}\n\n`);
|
||||
fs.appendFileSync(absolutePath, `${beforeStr}\n`);
|
||||
}
|
||||
},
|
||||
onStart: async (cp: ChildProcessWithoutNullStreams, startTime) => {
|
||||
await SubscriptionModel.update(
|
||||
{
|
||||
pid: cp.pid,
|
||||
},
|
||||
{ where: { id: doc.id } },
|
||||
);
|
||||
},
|
||||
onEnd: async (cp, endTime, diff) => {
|
||||
const sub = await this.getDb({ id: doc.id });
|
||||
const absolutePath = await this.handleLogPath(sub.log_path as string);
|
||||
|
@ -231,7 +238,7 @@ export default class SubscriptionService {
|
|||
let afterStr = '';
|
||||
try {
|
||||
if (sub.sub_after) {
|
||||
fs.appendFileSync(absolutePath, `\n\n## 执行after命令...\n`);
|
||||
fs.appendFileSync(absolutePath, `\n\n## 执行after命令...\n\n`);
|
||||
afterStr = await this.promiseExec(sub.sub_after);
|
||||
}
|
||||
} catch (error: any) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user