NestJS Scheduling

Manage distributed cron jobs with Redis locking and BullMQ queues in NestJS.

Updated Jan 22, 2026
One-click install
npx skills add https://github.com/ngxtm/skill-rule --skill nestjs-scheduling
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: NestJS Scheduling
Source: https://github.com/ngxtm/skill-rule/tree/main/rules/nestjs/scheduling
Command: npx skills add https://github.com/ngxtm/skill-rule --skill nestjs-scheduling

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the challenge of running scheduled tasks reliably in distributed environments, preventing duplicate job execution and ensuring task robustness.

Core Features & Use Cases

  • Distributed Cron Jobs: Prevents cron jobs from running on multiple instances simultaneously using Redis-based distributed locking.
  • Job Isolation & Robustness: Offloads heavy processing to background queues (like BullMQ) to avoid blocking the event loop and ensures proper error handling.
  • Use Case: Ensure a daily report generation task runs only once per day, even if multiple application instances are active, and that any failures in processing are caught and logged without crashing the application.

Quick Start

Configure the NestJS Scheduling skill to use Redis for distributed locking on the '@Cron' decorated method.

Frequently Asked Questions about NestJS Scheduling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent duplicate cron job execution in a clustered NestJS environment?

To prevent duplicate cron job execution in clustered NestJS environments, use Redis distributed locking on your scheduled methods. This ensures only a single instance acquires the lock and runs the job, while others skip the execution cycle.

How do I offload heavy background jobs in NestJS to avoid blocking the event loop?

To offload heavy background jobs in NestJS and avoid blocking the event loop, move the processing logic to BullMQ queue processors. This isolates robust task execution from the main application thread and ensures proper error handling.

Why do my NestJS scheduled tasks run multiple times simultaneously across instances?

NestJS scheduled tasks run multiple times simultaneously across instances because native cron decorators lack cluster-wide awareness. Implementing Redis distributed locking restricts job execution to a single instance per schedule trigger.

Does this approach support background job processing with BullMQ in NestJS?

Yes, this approach supports background job processing with BullMQ in NestJS. It integrates BullMQ queue processors to manage robust task execution, ensuring heavy work is offloaded and isolated from the main application flow.

What is the best way to ensure daily report generation runs only once in NestJS?

The best way to ensure daily report generation runs only once in NestJS is to combine cron decorators with Redis distributed locking. This guarantees the scheduled task executes on exactly one instance, even with multiple active instances.

When do I need distributed locking for NestJS scheduling?

You need distributed locking for NestJS scheduling when running clustered applications across multiple instances. It prevents duplicate task execution by ensuring only one instance processes the cron job at the scheduled time.