From b07faab7235a205b6767f25c1449a42f031303c0 Mon Sep 17 00:00:00 2001 From: ap <951984189@qq.com> Date: Thu, 6 Jan 2022 17:37:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/app/modules/task/queue/task.ts | 8 +++++--- src/app/modules/task/service/info.ts | 16 +++++++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 2dabf3e..10cb072 100755 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "@cool-midway/core": "^4.0.15", "@cool-midway/es": "^4.0.2", "@cool-midway/oss": "^4.0.3", - "@cool-midway/queue": "^4.1.0", + "@cool-midway/queue": "^4.1.2", "@cool-midway/redis": "^4.0.5", "@cool-midway/socket": "^4.0.2", "@cool-midway/wxpay": "^4.0.3", diff --git a/src/app/modules/task/queue/task.ts b/src/app/modules/task/queue/task.ts index 37f266d..a8f437b 100644 --- a/src/app/modules/task/queue/task.ts +++ b/src/app/modules/task/queue/task.ts @@ -21,10 +21,12 @@ export abstract class TaskInfoQueue extends BaseCoolQueue { const result = await this.taskInfoService.invokeService(job.data.service); this.taskInfoService.record(job.data, 1, JSON.stringify(result)); } catch (error) { - this.taskInfoService.record(job.data, 0, error); + this.taskInfoService.record(job.data, 0, error.message); + } + if (!job.data.isOnce) { + this.taskInfoService.updateNextRunTime(job.data.id); + this.taskInfoService.updateStatus(job.data.id); } - this.taskInfoService.updateNextRunTime(job.data.id); - this.taskInfoService.updateStatus(job.data.id); done(); } } diff --git a/src/app/modules/task/service/info.ts b/src/app/modules/task/service/info.ts index 9a689c7..2e6b995 100644 --- a/src/app/modules/task/service/info.ts +++ b/src/app/modules/task/service/info.ts @@ -71,11 +71,17 @@ export class TaskInfoService extends BaseService { async once(id) { const task = await this.taskInfoEntity.findOne({ id }); if (task) { - await this.taskInfoQueue.add(task, { - jobId: task.id.toString(), - removeOnComplete: true, - removeOnFail: true, - }); + await this.taskInfoQueue.add( + { + ...task, + isOnce: true, + }, + { + jobId: task.id.toString(), + removeOnComplete: true, + removeOnFail: true, + } + ); } }