Comments (14)
Yes, you'll need to create a module to reexport the BullModule
Here's an example:
import { BullModule, BullModuleOptions } from 'nest-bull'
import { Module } from '@nestjs/common'
import { ConfigModule } from 'src/config/config.module'
import { ConfigService } from 'src/config/config.service'
function redisOptions(configService: ConfigService) {
return {
host: configService.getString('REDIS_HOST'),
port: configService.getInt('REDIS_PORT'),
}
}
const BullQueueModule = BullModule.registerAsync([
{
name: 'email',
imports: [ConfigModule],
useFactory: (configService: ConfigService): BullModuleOptions => {
return {
name: 'email',
options: {
redis: redisOptions(configService),
},
}
},
inject: [ConfigService],
},
{
name: 'cron',
imports: [ConfigModule],
useFactory: (configService: ConfigService): BullModuleOptions => {
return {
name: 'cron',
options: {
redis: redisOptions(configService),
},
}
},
inject: [ConfigService],
},
])
@Module({
imports: [BullQueueModule],
exports: [BullQueueModule],
})
export class QueueModule { }
from bull.
@maxymshg you'll need to import the QueueModule
to the module you want to use it and then also setup your Processor on the Providers
email.module.ts
@Module({
imports: [
forwardRef(() => QueueModule),
],
providers: [EmailService, CronProcessor],
exports: [EmailService],
})
export class EmailModule {}
cron.processor.ts
@Injectable()
@Processor({ name: 'cron' })
export class CronProcessor {
private readonly logger = new Logger('EmailCron')
constructor(
@InjectQueue('email')
private queueService: Queue<EmailJob>,
@InjectQueue('cron')
private cron: Queue,
) {
this.logger.log('Intializing Cron Processor')
cron.add(null, {
repeat: { cron: '0 0 1-2 * * *' },
jobId: 'resume-email',
})
}
@Process()
async process(job: Job) {
this.logger.log('Resuming Email Service')
await this.queueService.resume()
}
}
Here's an example of a cron job that resume the email queue every 1-2 AM UTC if ever the quota has been reached.
from bull.
@smonv The queue can only be injected in the scope where BullModule
has been registered. That's why you can't directly inject it in another module without wrapping it in a service that you export. This is the expected behavior.
Also I don't think this has anything to do with what @jayakusumah and @captainjapeng are reporting.
@captainjapeng might be right here. There seems to be a confusion between the name of the options and the name of the queue. I'll see what can be done to prevent this kind of error.
EDIT:
Well, @captainjapeng is actually right.
BullModule.register
: theBullModuleOptions.name
is used as the queue name and as the queue injection token also.BullModule.registerAsync
: theBullModuleAsyncOptions.name
is used as the injection token and theBullModuleOptions.name
is used as the queue name.
from bull.
@jayakusumah Thanks for reporting this
I'll try to look into this issue in the next few days. It'd be great if, in the meantime, you could provide some code reproducing this error, or even submit a PR with failing tests.
from bull.
I got the same problem: controllers in others module cannot inject queue defined in another module.
I tried exports processors, import queue defined module but no luck.
https://github.com/smonv/bull-queue-test here is code for quick setup demo the problem
from bull.
I found a workaround to solve this problem. Instead of directed inject queue inside controller, indirect inject queue by a service.
Create a task service inside QueueModule
so naturally that service can inject queue. Export task service and let other controllers import it.
from bull.
Same issue, in my case I need to use registerAsync
so that I can load my ConfigService to get redis credentials from.
from bull.
I think I've found the issue, when you use registerAsync
it doesn't respect the name from the options and registering the ff instead of the name used in registerAsync
from bull.
I'm experiencing this same problem. Is there a work around at this moment?
from bull.
had the same issue.
really glad i found this thread here, otherwise there is no documentation yet.
It would be really great if it could be added to the readme. Thanks!
from bull.
Yes, you'll need to create a module to reexport the BullModule
Here's an example:
import { BullModule, BullModuleOptions } from 'nest-bull' import { Module } from '@nestjs/common' import { ConfigModule } from 'src/config/config.module' import { ConfigService } from 'src/config/config.service' function redisOptions(configService: ConfigService) { return { host: configService.getString('REDIS_HOST'), port: configService.getInt('REDIS_PORT'), } } const BullQueueModule = BullModule.registerAsync([ { name: 'email', imports: [ConfigModule], useFactory: (configService: ConfigService): BullModuleOptions => { return { name: 'email', options: { redis: redisOptions(configService), }, } }, inject: [ConfigService], }, { name: 'cron', imports: [ConfigModule], useFactory: (configService: ConfigService): BullModuleOptions => { return { name: 'cron', options: { redis: redisOptions(configService), }, } }, inject: [ConfigService], }, ]) @Module({ imports: [BullQueueModule], exports: [BullQueueModule], }) export class QueueModule { }
Hi @captainjapeng ,
Could you please share full example with usage, I tried re-export but still got same error.
from bull.
Got it, thanks for sharing this.
from bull.
Hi, I tried it, but i have the same problem. When you give a name (@processor({ name: 'foo' }), this.moduleRef.get cannot find the object. But it work very well with @processor({ name: '' }) and InjectQueue('').
from bull.
Let's track this here #171
from bull.
Related Issues (20)
- Bull Module not connecting as expected HOT 1
- Missing WorkerOptions types on BullQueueAdvancedProcessor and BullQueueAdvancedSeparateProcessor HOT 2
- options.family is not cast to number if given in REDIS_URL HOT 1
- Bull support for durable request scoped processors. HOT 4
- Give ability to disable job processing in `BullModule.forRoot` method HOT 4
- Mismatch with bull HOT 3
- NestJS Bull appears to be utilizing Upstash Redis unnecessarily. HOT 1
- Controls for nestjs/bullmq processors in request-scoped providers HOT 4
- Ability to accept/reject jobs before being processed HOT 1
- On application shutdown it closes all the queues. If any active job is creating more jobs it will fail. HOT 2
- Parametrized queue names HOT 1
- Windows sandboxed processors broke HOT 4
- When names of the Queue are unknown and provided via Async Config module HOT 4
- "Connection is closed" jest error when using bullmq > 5.1.11 HOT 3
- Issue with @InjectQueue decorator when used in a class that extends another class HOT 2
- Nestjs bull Consumer process() doesn't pick up job from queue to process HOT 1
- Queue Processor Not Closing in E2E Test Modules HOT 1
- Better way to get `QueueEventsListener` method types HOT 1
- Add repeatJobKey to Job interface HOT 1
- breaking change in @nestjs/bullmq v10.2.0 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bull.