Zum Hauptinhalt springen

Scheduler Architecture

Background task scheduling infrastructure.

Overview​

Gauzy uses multiple scheduling mechanisms:

  • NestJS Schedule β€” cron-based in-process tasks
  • BullMQ β€” Redis-backed job queues
  • Custom Timers β€” interval-based operations

Cron Scheduling​

import { Cron, CronExpression } from "@nestjs/schedule";

@Injectable()
export class CleanupService {
@Cron(CronExpression.EVERY_DAY_AT_MIDNIGHT)
async cleanupExpiredSessions() {
await this.sessionRepository
.createQueryBuilder()
.delete()
.where("expiresAt < :now", { now: new Date() })
.execute();
}

@Cron("0 */5 * * * *") // Every 5 minutes
async syncTimerStatus() {
await this.timerService.syncAllActiveTimers();
}
}

BullMQ Job Queues​

// Producer
@Injectable()
export class EmailService {
constructor(@InjectQueue("email") private emailQueue: Queue) {}

async sendWelcome(employee: IEmployee) {
await this.emailQueue.add("welcome", {
to: employee.user.email,
template: "welcome-user",
context: { firstName: employee.firstName },
});
}
}

// Consumer
@Processor("email")
export class EmailProcessor {
@Process("welcome")
async handleWelcome(job: Job) {
await this.mailerService.send(job.data);
}
}

Scheduled Tasks​

TaskSchedulePurpose
Session cleanupDaily midnightRemove expired
Timer syncEvery 5 minSync active timers
Report generationWeekly MondayGenerate reports
Backup triggerDaily 2 AMDatabase backup
Integration syncEvery hourSync external data