增加停止指定命令接口

This commit is contained in:
whyour
2023-05-01 22:56:47 +08:00
parent 8db997abe8
commit 0af687f781
5 changed files with 42 additions and 8 deletions
+19 -1
View File
@@ -9,7 +9,12 @@ import ScheduleService, { TaskCallbacks } from './schedule';
import { spawn } from 'child_process';
import SockService from './sock';
import got from 'got';
import { parseContentVersion, parseVersion } from '../config/util';
import {
getPid,
killTask,
parseContentVersion,
parseVersion,
} from '../config/util';
import { TASK_COMMAND } from '../config/const';
@Service()
@@ -178,4 +183,17 @@ export default class SystemService {
}
this.scheduleService.runTask(`real_time=true ${command}`, callback);
}
public async stop({ command }: { command: string }) {
if (!command.startsWith(TASK_COMMAND)) {
command = `${TASK_COMMAND} ${command}`;
}
const pid = await getPid(command);
if (pid) {
await killTask(pid);
return { code: 200 };
} else {
return { code: 400, message: '任务未找到' };
}
}
}