Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
657 views
in Technique[技术] by (71.8m points)

Create separate instance of service for @nestjs/bull

I am trying to make parallel queues for video processing.

However, I've faced problem in doing so. Below is the diagram of what i am trying to achieve.

enter image description here

Flow is:

  1. User sends GET request to the /process endpoint (actually, GET is only for testing, it rather uses @MessagePattern to receive data from other service)
  2. This request contains ModelDTO as well as sequence which is used for internal tracking
  3. Controller imports private readonly _queueService: QueueService via constructor
  4. It then calls this._queueService.process({ model, sequence })
  5. QueueService imports @InjectQueue('video_processor') private readonly _processorQueue: Queue via constructor
  6. QueueService simply calls this._processorQueue.add('process', data);
  7. VideoProcessor imports private readonly _videoService: VideoService via constructor
  8. Inside VideoProcessor there is a method with @Process('process') decorator
  9. Inside this method I am awaiting for the result from the service with await this._videoService.configure(job.data).process()

And here is the problem:

  1. Whenever I am trying to run 1 job at a time (sending single request and actually waiting for job to complete) everything works just fine
  2. If I am queueing two jobs at the same time, for some reason, the console.log(this._videoData.id) inside VideoService will now return the ID of the second model rather than actual ID.

So far I have tried adding scope: Scope.TRANSIENT to almost all services with no luck. Seems like i just can't figure out where this scope should be added.

enter image description here

I am expecting for 10 jobs to be able to run in parallel, however, if I add more than 1 job to the queue, they start mixing in data from the other jobs.

question from:https://stackoverflow.com/questions/65903284/create-separate-instance-of-service-for-nestjs-bull

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...