Background Job Architecture
Worker processes, job queues, and scheduled tasks.
Overviewβ
Gauzy uses BullMQ (Redis-backed) for background job processing:
Job Typesβ
| Queue | Jobs |
|---|---|
email | Send emails, notifications |
integration | Sync with third-party services |
screenshot | Process screenshots |
export | Export data to CSV/Excel |
import | Import data from files |
cleanup | Archive/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
Related Pagesβ
- Worker Architecture β worker process
- Redis & Caching β Redis infrastructure
- Scaling & HA β scaling workers