🏗️ Architecture

Background Job Architecture

Worker processes, job queues, and scheduled tasks.

Overview

Gauzy uses BullMQ (Redis-backed) for background job processing:

Diagram; its source is available below
Diagram source
graph LR
    API[API Server] -->|Enqueue| Redis[(Redis Queue)]
    Redis --> Worker1[Worker 1]
    Redis --> Worker2[Worker 2]
    Worker1 -->|Result| DB[(Database)]
    Worker2 -->|Result| DB

Job Types

QueueJobs
emailSend emails, notifications
integrationSync with third-party services
screenshotProcess screenshots
exportExport data to CSV/Excel
importImport data from files
cleanupArchive/delete old data

Creating a Job

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

  async sendWelcomeEmail(userId: string) {
    await this.emailQueue.add(
      "welcome",
      {
        userId,
        template: "welcome",
      },
      {
        attempts: 3,
        backoff: { type: "exponential", delay: 5000 },
      },
    );
  }
}

Processing a Job

@Processor("email")
export class EmailProcessor {
  @Process("welcome")
  async handleWelcome(job: Job) {
    const { userId, template } = job.data;
    await this.mailerService.send(userId, template);
  }
}

Scheduled Tasks

@Injectable()
export class CleanupService {
  @Cron("0 0 * * *") // Daily at midnight
  async cleanOldLogs() {
    await this.activityLogService.deleteOlderThan(90);
  }
}

Monitoring

Use Bull Dashboard for queue monitoring:

GET /admin/queues

Edit this page

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