🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@fluojs/queue

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fluojs/queue

Redis-backed background job processing with worker discovery and DLQ support for Fluo.

beta
Source
npmnpm
Version
1.0.0-beta.1
Version published
Weekly downloads
24
-88.24%
Maintainers
1
Weekly downloads
 
Created
Source

@fluojs/queue

English 한국어

Redis-backed distributed job processing for fluo. It features decorator-based worker discovery, automatic job serialization, and lifecycle-managed execution.

Table of Contents

Installation

npm install @fluojs/queue @fluojs/redis

When to Use

  • When you need to process long-running or resource-intensive tasks in the background.
  • When you want to decouple expensive operations (e.g., sending emails, image processing) from the request-response cycle.
  • When you need a distributed queue with retry logic, backoff, and dead-letter handling.

Quick Start

1. Define a Job and Worker

Create a job class and a worker class decorated with @QueueWorker.

import { QueueWorker } from '@fluojs/queue';

export class ProcessOrderJob {
  constructor(public readonly orderId: string) {}
}

@QueueWorker(ProcessOrderJob, { attempts: 3, backoff: { type: 'fixed', delayMs: 5000 } })
export class OrderWorker {
  async handle(job: ProcessOrderJob) {
    console.log(`Processing order: ${job.orderId}`);
    // Your logic here
  }
}

2. Register and Enqueue

Import QueueModule and inject QueueLifecycleService to enqueue jobs.

QueueModule.forRoot(...) is the supported root entrypoint for queue registration.

Use QueueModule.forRoot(...) for application-level queue registration.

import { Module, Inject } from '@fluojs/core';
import { QueueModule, QueueLifecycleService } from '@fluojs/queue';
import { RedisModule } from '@fluojs/redis';

@Module({
  imports: [
    RedisModule.forRoot({ host: 'localhost', port: 6379 }),
    QueueModule.forRoot(),
  ],
  providers: [OrderWorker],
})
export class AppModule {}

export class OrderService {
  @Inject(QueueLifecycleService)
  private readonly queue: QueueLifecycleService;

  async placeOrder(id: string) {
    await this.queue.enqueue(new ProcessOrderJob(id));
  }
}

Common Patterns

Named Redis Client

Leave clientName unset to keep using the default @fluojs/redis client from your app. If your queues should use a non-default Redis connection, set clientName to the name registered with RedisModule.forRootNamed(...).

QueueModule.forRoot({ clientName: 'jobs' })

Distributed Retries

Workers can be configured with a maximum number of attempts and backoff strategies to handle transient failures automatically.

@QueueWorker(MyJob, { 
  attempts: 5, 
  backoff: { type: 'exponential', delayMs: 1000 } 
})

Dead-Letter Handling

Jobs that fail all retry attempts are automatically moved to a dead-letter list in Redis (fluo:queue:dead-letter:<jobName>) for manual inspection or recovery.

QueueModule.forRoot() keeps the most recent 1_000 dead-letter entries per job by default. Set defaultDeadLetterMaxEntries: false to opt out, or provide a smaller positive number when operators need a tighter retention budget.

Treat low-level provider assembly as an internal implementation detail: low-level provider helpers are not part of the documented root-barrel contract.

Public API Overview

Core

  • QueueModule: Main entry point for queue registration.
  • QueueModule.forRoot(options): Registers queue support for an application module.
  • QueueLifecycleService: Primary service for enqueuing jobs (enqueue(job)).
  • @QueueWorker(JobClass, options?): Decorator to mark a class as a job handler.

Types

  • QueueModuleOptions: Global queue settings (clientName, default attempts, concurrency, rate limiting).
  • QueueWorkerOptions: Per-job settings (attempts, backoff, concurrency, jobName, rate limiting).
  • QueueBackoffOptions: Retry backoff settings (type, delayMs).

QueueModuleOptions also includes dead-letter retention controls such as defaultDeadLetterMaxEntries.

  • @fluojs/redis: Required as the backing store for job persistence.
  • @fluojs/cron: For scheduled/recurring background tasks.

Example Sources

  • packages/queue/src/module.test.ts: Worker discovery and enqueueing tests.
  • packages/queue/src/public-surface.test.ts: Public API contract verification.

Keywords

fluo

FAQs

Package last updated on 24 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts