Skip to content

feat: add queue alerts feature#1061

Open
mo3tazda3na wants to merge 1 commit intofelixmosh:masterfrom
mo3tazda3na:feat/queue-alerts
Open

feat: add queue alerts feature#1061
mo3tazda3na wants to merge 1 commit intofelixmosh:masterfrom
mo3tazda3na:feat/queue-alerts

Conversation

@mo3tazda3na
Copy link
Copy Markdown

feat: Add Queue Alerts system

Summary

This PR adds a new feature that allows users to configure automated alerts based on queue job counts. Users can define thresholds for specific job statuses (e.g., failed, waiting, active) and receive a callback notification when those thresholds are exceeded.

Key Features

  • Flexible Configuration: Supports global defaults and per-queue overrides.
  • Specific Status Monitoring: Monitor any job status (active, failed, waiting, delayed, etc.).
  • Smart Alerting: Includes a steps option to prevent alert fatigue. For example, if threshold is 10 and steps is 5, alerts will trigger at 15, 20, 25, etc., rather than on every single increment.
  • Zero UI Overhead: This runs on the server side within the API adapter.

Configuration Example

You can configure alerts by passing the queueAlerts option to createBullBoard:

const { createBullBoard } = require('@bull-board/api');
const { BullMQAdapter } = require('@bull-board/api/bullMQAdapter');
const { ExpressAdapter } = require('@bull-board/express');

createBullBoard({
  queues: [new BullMQAdapter(myQueue)],
  serverAdapter,
  options: {
    queueAlerts: {
      checkInterval: 60 * 1000, // Optional: Check every 1 minute (default)
      
      // Callback to handle the alert (e.g. send to Slack / Email / PagerDuty)
      onAlert: (data) => {
        console.log(`Alert detected for queue ${data.queueName}:`, data);
        // data = { queueName: 'BullMQ', status: 'failed', count: 12, threshold: 10 }
      },

      config: {
        // Global defaults applied to all queues
        default: {
          failed: { 
            count: 10, // Alert if more than 10 failed jobs
            steps: 5   // Alert again at 15, 20, 25...
          },
          waiting: { 
            count: 1000, // Alert if backlog > 1000
            steps: 100 
          }
        },

        // Per-queue overrides
        'Specific-Critical-Queue': {
          failed: { 
            count: 1, // Stricter threshold for critical queue
            steps: 1 
          }
        }
      }
    }
  }
});

Checklist

  • Implementation of QueueAlarms class
  • Integration with createBullBoard
  • Type definitions updated
  • Unit tests added and passing
  • Examples updated

- Added QueueAlarms class to handle queue threshold alerts
- Updated BoardOptions to include queueAlerts configuration
- Added unit tests for QueueAlarms
- Updated examples to demonstrate usage
@felixmosh
Copy link
Copy Markdown
Owner

Hi @mo3tazda3na why do you think that this feature should be part of this lib?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants