[英]How to set "status" in queue
I have a function which add me to queue a job like this:我有一个函数可以将我添加到这样的作业队列中:
async addJob(someParameters: SomeParameters): Promise<void> {
await this.saveToDb(someParameters);
try {
await this.jobQueue.add('job', {
someParameters
})
} catch (error) {
}
}
but before adding to queue I save my data in database.但在添加到队列之前,我将数据保存在数据库中。 My entity have a enum field "Status" with some parameters.我的实体有一个带有一些参数的枚举字段“状态”。
In my job.process.ts
i have my queue processor:在我的job.process.ts
我有我的队列处理器:
@Process('job')
async runJob(job: Job<{param: SomeParameters}>): Promise<any> {
try {
await this.launchMyFunction(param);
}
}
}
and another function to monitoring a job in the queue:以及另一个监视队列中作业的功能:
@OnQueueCompleted()
async onCompleted(job: Job): Promise<void> {
await this.updateJobStatus(here must be ID from DB); //HERE IS PROBLEM
}
and right now i have a problem, how to get and ID from my databse of the current job in queue and set a status to this record in database?现在我有一个问题,如何从队列中当前作业的数据库中获取和 ID 并在数据库中为该记录设置状态?
您可以使用作业ID,并在进程中的作业参数中获取它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.