Skip to content

Allow sharing 2 connections, one for queues and another for workers to optimize the connection behavior for each #91

@omardoma

Description

@omardoma

BullMQ's Production Checklist advises that Queue operations should fail fast while Worker operations should be long running and be tolerant to errors/failures.

So ideally we would create 2 connections in config/redis.ts:

import { defineConfig } from '@adonisjs/redis'

const redisConfig = defineConfig({
    queue: {
      host: env.get('REDIS_HOST'),
      port: env.get('REDIS_PORT'),
      password: env.get('REDIS_PASSWORD'),
      db: 0,
      retryStrategy(times) {
        return Math.min(times * 1000, 20000) // 1s min, 20s max
      },
      maxRetriesPerRequest: 3,
      enableReadyCheck: true,
      enableOfflineQueue: false,
    },
    worker: {
      host: env.get('REDIS_HOST'),
      port: env.get('REDIS_PORT'),
      password: env.get('REDIS_PASSWORD'),
      db: 0,
      retryStrategy(times) {
        return Math.min(times * 1000, 20000) // 1s min, 20s max
      },
      maxRetriesPerRequest: null, // See https://docs.bullmq.io/guide/going-to-production#maxretriesperrequest
      enableReadyCheck: true,
      enableOfflineQueue: true,
    },
}

export default redisConfig

declare module '@adonisjs/redis/types' {
  export interface RedisConnections extends InferConnections<typeof redisConfig> {}
}

and then in config/queue.ts:

import { defineConfig } from '@nemoventures/adonis-jobs'

const queueConfig = defineConfig({
  connection: {
    queueConnectionName: 'queue',
    workerConnectionName: 'worker',
  },
  useSharedConnection: true,
}

export default queueConfig
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions