🏗️ Architecture

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

Edit this page

Copyright © 2023-Present Ever Co. LTD.Docs by Sourcey