Why Use This
This skill provides specialized capabilities for HoangNguyen0403's codebase.
Use Cases
- Developing new features in the HoangNguyen0403 repository
- Refactoring existing code to follow HoangNguyen0403 standards
- Understanding and working with HoangNguyen0403's codebase structure
Install Guide
2 steps - 1
- 2
Install inside Ananke
Click Install Skill, paste the link below, then press Install.
https://github.com/HoangNguyen0403/agent-skills-standard/tree/develop/skills/nestjs/scheduling
Skill Snapshot
Auto scan of skill assets. Informational only.
Valid SKILL.md
Checks against SKILL.md specification
Source & Community
Updated At Jan 18, 2026, 04:24 AM
Skill Stats
SKILL.md 42 Lines
Total Files 1
Total Size 0 B
License NOASSERTION
---
name: NestJS Scheduling
description: Distributed cron jobs and locking patterns.
metadata:
labels: [nestjs, cron, scheduling, redis]
triggers:
files: ['**/*.service.ts']
keywords: [@Cron, CronExpression, ScheduleModule]
---
# Task Scheduling & Jobs
## **Priority: P1 (OPERATIONAL)**
Background job processing and scheduled task patterns.
- **Problem**: `@Cron()` runs on **every** instance. In K8s with 3 pods, your "Daily Report" runs 3 times.
- **Solution**: **Distributed Locking** using Redis.
- **Pattern**: Using a decorator to wrap the cron method.
- **Logic**: `SET resource_name my_random_value NX PX 30000` (Redis Atomic Set).
## Cron Decorator Pattern
- **Implementation**:
```typescript
@Cron(CronExpression.EVERY_MINUTE)
@DistributedLock({ key: 'send_emails', ttl: 5000 })
async handleCron() {
// Only runs if lock acquired
}
```
- **Tools**: Use `nestjs-redlock` or custom Redis wrapper via `redlock` library.
## Job Robustness
- **Isolation**: Never perform heavy processing inside the Cron handler.
- **Pattern**: Cron -> Push Job ID to Queue (BullMQ) -> Worker processes it.
- **Why**: Cron schedulers can get blocked by the Event Loop; Workers are scalable.
- **Error Handling**: Wrap ALL cron logic in `try/catch`. Uncaught exceptions in a Cron job can crash the entire Node process.