Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import { Processor, WorkerHost } from '@nestjs/bullmq'; import { Job } from 'bullmq'; import { Logger } from '@nestjs/common'; import { ProjectService } from '../services/project.service'; import { ProjectBudgetService } from '../services/project-budget.service'; import { TimesheetService } from '../services/timesheet.service'; @Processor('projects-queue') export class ProjectProcessor extends WorkerHost { private readonly logger = new Logger(ProjectProcessor.name); constructor( private readonly projectService: ProjectService, private readonly budgetService: ProjectBudgetService, private readonly timesheetService: TimesheetService, ) { super(); } async process(job: Job<any, any, string>): Promise<any> { this.logger.log(`Processing job ${job.name} (ID: ${job.id})`); switch (job.name) { case 'calculate-project-health': return this.handleCalculateProjectHealth(job.data); case 'forecast-budget': return this.handleForecastBudget(job.data); case 'auto-submit-timesheets': return this.handleAutoSubmitTimesheets(job.data); default: this.logger.warn(`Unknown job name: ${job.name}`); } } private async handleCalculateProjectHealth(data: any): Promise<any> { const { tenantId, projectId } = data; this.logger.log( `Calculating health for project ${projectId} (Tenant: ${tenantId})`, ); // Implementation for health calculation... return { status: 'success', health: 'on_track' }; } private async handleForecastBudget(data: any): Promise<any> { const { tenantId, projectId } = data; this.logger.log( `Forecasting budget for project ${projectId} (Tenant: ${tenantId})`, ); const snapshot = await this.budgetService.getSnapshot(tenantId, projectId); return { status: 'success', snapshot }; } private async handleAutoSubmitTimesheets(data: any): Promise<any> { const { tenantId } = data; this.logger.log(`Auto-submitting timesheets for tenant ${tenantId}`); // Implementation for auto-submitting timesheets at end of period... return { status: 'success' }; } } |