修复任务无法停止

This commit is contained in:
ap 2022-01-24 16:26:11 +08:00
parent 0463738b53
commit 3c8f48f4f5

View File

@ -40,9 +40,10 @@ export class TaskInfoService extends BaseService {
async stop(id) {
const task = await this.taskInfoEntity.findOne({ id });
if (task) {
const job = await this.exist(task.id);
const result = await this.taskInfoQueue.getRepeatableJobs();
const job = _.find(result, { id: task.id + '' });
if (job) {
await this.taskInfoQueue.removeRepeatable(JSON.parse(task.repeatConf));
await this.taskInfoQueue.removeRepeatableByKey(job.key);
}
task.status = 0;
await this.taskInfoEntity.update(task.id, task);
@ -115,9 +116,7 @@ export class TaskInfoService extends BaseService {
if (params.status === 1) {
const exist = await this.exist(params.id);
if (exist) {
await this.taskInfoQueue.removeRepeatable(
JSON.parse(params.repeatConf)
);
this.stop(params.id);
}
const { every, limit, startDate, endDate, cron } = params;
const repeat = {
@ -169,7 +168,7 @@ export class TaskInfoService extends BaseService {
const task = await this.taskInfoEntity.findOne({ id });
const exist = await this.exist(task.id);
if (exist) {
await this.taskInfoQueue.removeRepeatable(JSON.parse(task.repeatConf));
this.stop(task.id);
}
await this.taskInfoEntity.delete({ id });
await this.taskLogEntity.delete({ taskId: id });