完善定时任务

This commit is contained in:
ap 2022-01-06 17:37:24 +08:00
parent 28f624420a
commit b07faab723
3 changed files with 17 additions and 9 deletions

View File

@ -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",

View File

@ -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();
}
}

View File

@ -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,
}
);
}
}