stencil icon indicating copy to clipboard operation
stencil copied to clipboard

[stencil] [C4GT] Queues with bull

Open techsavvyash opened this issue 1 year ago • 32 comments

Add Queues with Bull to Stencil NestJS Project

Description

The task involves integrating Bull, a JavaScript library for managing job queues in Node.js, into Stencil. This addition will enable the project to efficiently handle and manage asynchronous tasks using job queues.

Goals

  1. Bull Integration: Successfully integrate and equip Stencil with Bull.

  2. Job Queue Implementation: Implement job queues using Bull for at least two distinct asynchronous tasks within the Stencil.

  3. Concurrency Control: Configure and optimize Bull job queues for efficient concurrency control, balancing workload and resource utilization.

Acceptance Criteria

  1. Bull Setup: Install and configure the Bull library in Stencil.

  2. Job Queue Implementation: Create and integrate at least three different job queues for distinct asynchronous tasks in the project.

  3. Concurrency Control Testing: Perform testing to ensure that concurrency control is effectively managed, preventing issues related to job processing overload or resource exhaustion.

  4. Documentation Update: Provide comprehensive documentation on your work. Include it in the form of a READMe.md in the specific module you create. It will be added to the official Stencil Docs.

Checklist (To be filled by the developer)

  • [ ] Install Bull library in the Stencil NestJS project.
  • [ ] Configure Bull to work seamlessly within the project.
  • [ ] Implement at least three distinct job queues for different asynchronous tasks.
  • [ ] Implement error handling mechanisms for graceful error management.
  • [ ] Test concurrency control to ensure efficient job processing.
  • [ ] Update documentation with comprehensive information on Bull integration and job queue implementation details.

Product Name

Stencil

Organisation Name

SamagraX

Tech Skills Needed

TypeScript, APIs, Queues, Bull

Mentors

@RyanWalker277

Complexity

Hard

Domain

Category

Backend

Sub Category

APIs, Queues, Bull

techsavvyash avatar Jan 05 '24 04:01 techsavvyash

Hii @techsavvyash @RyanWalker277 I would like to give an attempt to this issue under your mentorship!! I have a few things to ask:

  1. can you give me more info about the the async tasks for which the job queue is needed to be implemented.
  2. Also is redis already connected to the project? As i know redis is required by bull to implement the job queues
  3. Is bull needed to be installed in stencil or in any of its specific packages folder?
  4. Can you provide some resource to understand what stencil is actually working to achieve and its workflow and understanding the project in depth

Thanks

amansgith avatar Feb 21 '24 17:02 amansgith

Hi @amansgith, Thanks for the detailed query, i'll try to provide some clarity on your queries:

  1. Bull is to be used to enable the capability of asyn events in stencil so the implementation needs to be generic enough to provide an interface to implement async processing fast.
  2. Redis containers can be found connected to the project in the current state of stencil.
  3. Bull needs to be installed in the specific component that you will create to expose the interface to setup the tooling around bull, these components might be a controller, service, interceptor, module etc. which we might find required to help bootstrap bull faster in our stencil project.
  4. Stencil is an Opinionated backend framework with a primary objective of reducing the developer time in setting up boilerplagte tooling which remains same across projects. The workflow is simple as of now, we have a common folder inside the repository which hosts the pre-defined components that we publish as a part of the @samagra-x/stencil package to enable the current functionalities that stencil supports, other than that we have the examples folder which demonstrates via working examples how to setup a particular feature that stencil provides.

Hope this helps provide clarity :)

techsavvyash avatar Feb 21 '24 17:02 techsavvyash

Thanks @techsavvyash this clears a lot!! i will proceed with it and will get back if anythings bugs me..

amansgith avatar Feb 21 '24 18:02 amansgith

Hey @amansgith , How is it going?

techsavvyash avatar Feb 29 '24 04:02 techsavvyash

Hi @techsavvyash I am currently learning about How to use queues.. it's my first time picking up such an issue where the software itself works as a boilerplate for other applications So it's going a little hard for me.. I Request if anyone else wants go ahead with the issue.. they are welcome!! Sorry for no progress.

amansgith avatar Feb 29 '24 08:02 amansgith

Hey @amansgith, Thanks for taking interest, and we do realise it might be something new for you. Please let me know in case you need some support.

techsavvyash avatar Feb 29 '24 08:02 techsavvyash

Hey @amansgith, Thanks for taking interest, and we do realise it might be something new for you. Please let me know in case you need some support.

Sure thing!! Thank you so much

amansgith avatar Feb 29 '24 13:02 amansgith

@techsavvyash I understand the problem, and I believe I have the necessary skills. Could I have the opportunity to work on this?

Yash-Sajwan24 avatar Mar 17 '24 09:03 Yash-Sajwan24

@Yash-Sajwan24 please go right ahead!

techsavvyash avatar Mar 17 '24 09:03 techsavvyash

Hello ,@techsavvyash I am working on this issue and I have a few queries. 1- I am thinking about setting the BullMq service inside the common/servics and making it a global module so that we can inject it as a dependency whrever required. 2- Additionally I was thinking about implementing the job queues for the file upload service to manage file upload and fallback 3- Can you give me some information about the environment variables, like the redis connection url etc. Thank you.

saksham-tomer avatar Mar 24 '24 12:03 saksham-tomer

I'll also give it a try

Savio629 avatar Mar 24 '24 14:03 Savio629

@techsavvyash I tried intergrating bull in 04-monitoring sample with the help of a youtube tutorial to understand it and it works fine with the sample. I have attached a implementation video below:

(The implementation just shows transcoding a message (or a audio file) with the help of queue)

https://github.com/SamagraX-Stencil/stencil/assets/91362589/62f8e08f-698e-4f25-9859-4dc3c32980ca

Bull needs to be installed in the specific component that you will create to expose the interface to setup the tooling around bull, these components might be a controller, service, interceptor, module etc. which we might find required to help bootstrap bull faster in our stencil project.

So what I understand is we need to implement bull for these components such as a controller, service, interceptor, module etc. Example: Let's say under controller we need to implement Bull for processing uploaded files asynchronously... https://github.com/SamagraX-Stencil/stencil/blob/main/packages/common/src/controllers/file-upload.controller.ts#L20

Savio629 avatar Mar 24 '24 16:03 Savio629

@techsavvyash I tried intergrating bull in 04-monitoring sample with the help of a youtube tutorial to understand it and it works fine with the sample. I have attached a implementation video below:

(The implementation just shows transcoding a message (or a audio file) with the help of queue)

bull-04monitoring.mp4

Bull needs to be installed in the specific component that you will create to expose the interface to setup the tooling around bull, these components might be a controller, service, interceptor, module etc. which we might find required to help bootstrap bull faster in our stencil project.

So what I understand is we need to implement bull for these components such as a controller, service, interceptor, module etc. Example: Let's say under controller we need to implement Bull for processing uploaded files asynchronously... https://github.com/SamagraX-Stencil/stencil/blob/main/packages/common/src/controllers/file-upload.controller.ts#L20

I am having issues running the instance locally --> Error: Cannot find module 'C:\Users\saksh\Videos\stencilNew\stencil\stencil\packages\common\dist\main' at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1149:15) at Function.Module._load (node:internal/modules/cjs/loader:990:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12) at node:internal/main/run_main_module:28:49 from where did you spin up the server ?

saksham-tomer avatar Mar 24 '24 16:03 saksham-tomer

Trying running it on gitpod

Savio629 avatar Mar 24 '24 16:03 Savio629

Trying running it on gitpod 👍 Thanks

saksham-tomer avatar Mar 24 '24 16:03 saksham-tomer

@Savio629 the video looks good. You are on the right track, what we need is to add the components (modules, services, etc.) required to setup the bull in a Nest/Stencil app, as first class citizens in the stencil packages. Take for example how we have added the Monitoring module, Temporal module etc.

techsavvyash avatar Mar 24 '24 17:03 techsavvyash

So what I understood is that I need to add job queues using bull for handling async tasks over this modules (Monitoring, file uploads,etc ), right? Or create a separate module(is this what you meant by first class citizen?) for bull for handling job queues and then integrating them inside/over the specified module? @techsavvyash

Savio629 avatar Mar 31 '24 07:03 Savio629

Or create a separate module(is this what you meant by first class citizen?) for bull for handling job queues and then integrating them inside/over the specified module?

this is the correct assumption @Savio629. We need to be able to setup bull in any stencil app and then bootstrap it using interceptors or whatever other component we require to any api endpoints the user might want to.

techsavvyash avatar Apr 01 '24 05:04 techsavvyash

@techsavvyash Right now I was trying it with file-upload by updating the packages of file-upload Ref: https://medium.com/@raviyasas/how-to-use-bull-with-nestjs-18697f123e3c Am I on right track?

Savio629 avatar Apr 15 '24 15:04 Savio629

What exactly are you trying to do by manipulating the file-upload package?

techsavvyash avatar Apr 16 '24 09:04 techsavvyash

@techsavvyash Is this issue opened??

ishqDehlvi avatar Jun 19 '24 09:06 ishqDehlvi

Yes @ishqDehlvi

techsavvyash avatar Jun 19 '24 09:06 techsavvyash

Hello @techsavvyash, Is this issue still open? If so, could you please provide more details about it so that I can start working on it?

Soham-27 avatar Aug 08 '24 04:08 Soham-27

Please assign this issue to me under C4GT

vishalmaurya850 avatar Aug 08 '24 10:08 vishalmaurya850

Assigning to @Soham-27 @vishalmaurya850 You can also start working collaboratively on the issue

Savio629 avatar Aug 08 '24 16:08 Savio629

Hey @Soham-27 @vishalmaurya850 Thanks for showing interest in the issue, please connect with @Savio629 to get more context around the issue, but an assignment would only once you have raised a draft PR for the issue.

techsavvyash avatar Aug 12 '24 08:08 techsavvyash

Hey

MohitNSamagra avatar Aug 13 '24 08:08 MohitNSamagra

Hello @MohitNSamagra,

Are you involved in the Stencil project?

Soham-27 avatar Aug 13 '24 08:08 Soham-27

Hi

jaanbaaz avatar Aug 13 '24 09:08 jaanbaaz

@techsavvyash Please assign me this issue

JiyaGupta-cs avatar Sep 24 '24 10:09 JiyaGupta-cs