npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@asyncview/nestjs

v0.8.0

Published

AsyncView SDK for NestJS - Background job observability

Downloads

71

Readme

@asyncview/nestjs

AsyncView SDK for NestJS - Native queue observability for BullMQ and @nestjs/schedule through automatic event capture.

Installation

npm install @asyncview/nestjs

Quick Start

Simply add AsyncViewModule to your app and you're done! AsyncView will automatically discover all your @Processor decorated classes as well as all your @Cron, @Interval, and @Timeout decorated classes and start capturing events.

With BullMQ (@nestjs/bullmq)

import { Module } from '@nestjs/common'
import { BullModule } from '@nestjs/bullmq'
import { ScheduleModule } from '@nestjs/schedule'
import { AsyncViewModule } from '@asyncview/nestjs'

@Module({
  imports: [
    BullModule.forRoot({
      connection: {
        host: 'localhost',
        port: 6379,
      },
    }),
    ScheduleModule.forRoot(),
    // Make sure you import AsyncViewModule after all other modules
    AsyncViewModule.forRoot({
      hubUrl: 'https://your-asyncview-hub.com',
      systemToken: 'asyncview_sys_your_token_here',
    }),
  ],
})
export class AppModule {}

Example BullMQ Processor

import { Processor, WorkerHost } from '@nestjs/bullmq'
import { Job } from 'bullmq'

@Processor('email-queue')
export class EmailProcessor extends WorkerHost {
  async process(job: Job): Promise<void> {
    // Your job processing logic
    // AsyncView automatically captures all job events!
  }
}

With @nestjs/schedule

import { Injectable } from '@nestjs/common'
import { Cron, Interval, Timeout } from '@nestjs/schedule'

@Injectable()
export class TasksService {
  @Cron('0 0 * * *', { name: 'daily-cron' })
  handleDailyCron() {
    // AsyncView automatically tracks execution, duration, and failures
  }

  @Interval(10000, { name: 'interval' })
  handleInterval() {
    // Tracked as scheduler:interval
  }

  @Timeout(5000, { name: 'timeout' })
  handleTimeout() {
    // Tracked as scheduler:timeout
  }
}


That's it! AsyncView will automatically discover and attach to all your processors and schedulers.

## Configuration

```typescript
AsyncViewModule.forRoot({
  hubUrl: string                     // Required: AsyncView hub URL
  systemToken: string                // Required: System-specific token
  captureJobData?: boolean           // Default: true
  captureFailedReason?: boolean      // Default: true
  captureStackTrace?: boolean        // Default: false
  scrubFields?: string[]             // Fields to redact, e.g., ['password', 'ssn']
  sampleRate?: number                // Default: 1.0 (100% of jobs)
  batchSize?: number                 // Default: 100
  flushInterval?: number             // Default: 1000ms
  maxRetries?: number                // Default: 20
  initialRetryDelay?: number         // Default: 1000ms
  maxRetryDelay?: number             // Default: 180000ms (3 minutes)
  retryBackoffMultiplier?: number    // Default: 2
  environment?: string               // Default: process.env.NODE_ENV
  version?: string                   // Default: process.env.npm_package_version
  hostname?: string                  // Default: os.hostname()
})

Privacy & Performance

Data Scrubbing

Protect sensitive information with powerful field scrubbing that supports nested keys, arrays, and wildcards:

AsyncViewModule.forRoot({
  hubUrl: '...',
  systemToken: '...',
  scrubFields: [
    'password',              // Top-level fields
    'user.email',            // Nested fields
    'users[].ssn',           // Fields in arrays
    '*.apiKey',              // Any immediate child's apiKey
    '**.token',              // Any token at any depth
  ],
})

Sampling

For high-throughput queues, reduce overhead by sampling:

AsyncViewModule.forRoot({
  hubUrl: '...',
  systemToken: '...',
  sampleRate: 0.1, // Monitor 10% of jobs
})

Retry Configuration

The SDK includes automatic retry with exponential backoff for hub failures:

AsyncViewModule.forRoot({
  hubUrl: '...',
  systemToken: '...',
  maxRetries: 20,
  initialRetryDelay: 1000,
  maxRetryDelay: 180000,
  retryBackoffMultiplier: 2,
})

Default settings provide ~40 minutes of retry tolerance, ensuring events aren't lost during temporary hub outages.

Queue Library Support

AsyncView automatically detects and supports both queue libraries:

  • BullMQ (bullmq + @nestjs/bullmq) - The modern, Redis-based queue library
  • @nestjs/schedule (@nestjs/schedule) - The schedule library for cron, interval, and timeout jobs

You only need to install the queue library you're using. AsyncView will automatically:

  1. Detect which library is installed
  2. Initialize the appropriate adapter
  3. Discover and attach to your @Processor decorated classes
  4. Discover and attach to your @Cron, @Interval, and @Timeout decorated classes

Events Captured

Queue Jobs (Both BullMQ and Bull)

The SDK automatically captures:

  • job.created - When a job is added to the queue
  • job.active - When a worker picks up a job
  • job.completed - When a job finishes successfully
  • job.failed - When a job fails

Scheduled Tasks

The SDK automatically captures @nestjs/schedule decorators:

  • schedule.started - When a scheduled task starts execution
  • schedule.completed - When a scheduled task completes successfully
  • schedule.failed - When a scheduled task fails

Supported decorators:

  • @Cron() - Cron-based scheduling
  • @Interval() - Interval-based scheduling
  • @Timeout() - One-time timeout-based scheduling