You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Am trying to use bullmq with adonisjs but have run into some issues which I have resolved.
First of there is no documentation on how to set up BullMQ in adonisjs, so what I did is that I created a provider and added the code in ready method of the provider as below.
importtype{ApplicationService}from'@adonisjs/core/types';importmailfrom'@adonisjs/mail/services/main';import{Queue,QueueEvents,Worker}from'bullmq';exportdefaultclassEmailQueueProvider{constructor(protectedapp: ApplicationService){}/** * Register bindings to the container */register(){}/** * The container bindings have booted */asyncboot(){}/** * The application has been booted */asyncstart(){}/** * The process has been started */asyncready(){constemailsQueue=newQueue('emails');mail.setMessenger(mailer=>{return{asyncqueue(mailMessage,config){awaitemailsQueue.add('send_email';},};});constworker=newWorker('emails',asyncjob=>{if(job.name==='send_email'){const{ mailMessage, config, mailerName }=job.data;awaitmail.use(mailerName).sendCompiled(mailMessage,config);}},{connection: {host: '127.0.0.1',port: 6379,},},);worker.on('completed',job=>{console.log(`${job.id} has completed!`);});worker.on('failed',(job,err)=>{console.log(`${job?.id} has failed with ${err.message}`);});constqueueEvents=newQueueEvents('emails');queueEvents.on('waiting',({ jobId })=>{console.log(`A job with ID ${jobId} is waiting`);});queueEvents.on('active',({ jobId, prev })=>{console.log(`Job ${jobId} is now active; previous status was ${prev}`);});queueEvents.on('completed',({ jobId, returnvalue })=>{console.log(`${jobId} has completed and returned ${returnvalue}`);});queueEvents.on('failed',({ jobId, failedReason })=>{console.log(`${jobId} has failed with reason ${failedReason}`);});}/** * Preparing to shutdown the app */asyncshutdown(){}}
but am getting this error
update providers/email_queue_provider.ts
╭─────────────────────────────────────────────────╮
│ │
│ Server address: http://localhost:3333 │
│ File system watcher: enabled │
│ Ready in: 701 ms │
│ │
╰─────────────────────────────────────────────────╯
Error: Worker requires a connection
at EmailQueueProvider.ready providers/email_queue_provider.ts:41
36| });
37| },
38| };
39| });
40|
❯ 41| const worker = new Worker(
42|'emails',
43| async job => {
44|if (job.name === 'send_email') {
45| const { mailMessage, config, mailerName } = job.data;
46|
⁃ Worker
node_modules/.pnpm/bullmq@5.7.5/node_modules/bullmq/src/classes/worker.ts:210
⁃ ProvidersManager.ready
node_modules/.pnpm/@adonisjs+application@8.2.1_@adonisjs+config@5.0.1_@adonisjs+fold@10.1.1/node_modules/@adonisjs/application/src/managers/providers.ts:197
⁃ Application.start
node_modules/.pnpm/@adonisjs+application@8.2.1_@adonisjs+config@5.0.1_@adonisjs+fold@10.1.1/node_modules/@adonisjs/application/src/application.ts:563
[18:42:54.894] INFO (73086): started HTTP server on localhost:3333
If I manually add the connection host and port it works fine
importtype{ApplicationService}from'@adonisjs/core/types';importmailfrom'@adonisjs/mail/services/main';import{Queue,QueueEvents,Worker}from'bullmq';exportdefaultclassEmailQueueProvider{constructor(protectedapp: ApplicationService){}/** * Register bindings to the container */register(){}/** * The container bindings have booted */asyncboot(){}/** * The application has been booted */asyncstart(){}/** * The process has been started */asyncready(){constemailsQueue=newQueue('emails');mail.setMessenger(mailer=>{return{asyncqueue(mailMessage,config){awaitemailsQueue.add('send_email',{
mailMessage,
config,mailerName: mailer.name,});},};});constworker=newWorker('emails',asyncjob=>{if(job.name==='send_email'){const{ mailMessage, config, mailerName }=job.data;awaitmail.use(mailerName).sendCompiled(mailMessage,config);}},{connection: {host: '127.0.0.1',port: 6379,},},);worker.on('completed',job=>{console.log(`${job.id} has completed!`);});worker.on('failed',(job,err)=>{console.log(`${job?.id} has failed with ${err.message}`);});constqueueEvents=newQueueEvents('emails');queueEvents.on('waiting',({ jobId })=>{console.log(`A job with ID ${jobId} is waiting`);});queueEvents.on('active',({ jobId, prev })=>{console.log(`Job ${jobId} is now active; previous status was ${prev}`);});queueEvents.on('completed',({ jobId, returnvalue })=>{console.log(`${jobId} has completed and returned ${returnvalue}`);});queueEvents.on('failed',({ jobId, failedReason })=>{console.log(`${jobId} has failed with reason ${failedReason}`);});}/** * Preparing to shutdown the app */asyncshutdown(){}}
Is it not supposed to work with the connection provided by redis that I have already set.
here is the redis config.
importenvfrom'#start/env'import{defineConfig}from'@adonisjs/redis'import{InferConnections}from'@adonisjs/redis/types'constredisConfig=defineConfig({connection: 'main',connections: {/* |-------------------------------------------------------------------------- | The default connection |-------------------------------------------------------------------------- | | The main connection you want to use to execute redis commands. The same | connection will be used by the session provider, if you rely on the | redis driver. | */main: {host: env.get('REDIS_HOST'),port: env.get('REDIS_PORT'),password: env.get('REDIS_PASSWORD',''),db: 0,keyPrefix: '',retryStrategy(times){returntimes>10 ? null : times*50},},},})exportdefaultredisConfigdeclare module '@adonisjs/redis/types'{exportinterfaceRedisConnectionsextendsInferConnections<typeofredisConfig>{}}
Redis connection is working fine
Reproduction repo
No response
The text was updated successfully, but these errors were encountered:
Package version
^6.6.0
Describe the bug
Am trying to use bullmq with adonisjs but have run into some issues which I have resolved.
First of there is no documentation on how to set up BullMQ in adonisjs, so what I did is that I created a provider and added the code in ready method of the provider as below.
but am getting this error
If I manually add the connection host and port it works fine
Is it not supposed to work with the connection provided by redis that I have already set.
here is the redis config.
Redis connection is working fine
Reproduction repo
No response
The text was updated successfully, but these errors were encountered: