11import { Inject , Injectable , forwardRef } from '@nestjs/common' ;
2- import Agenda from 'agenda' ;
32import { mongo } from 'mongoose' ;
43
54import { AirportService } from '../airport/airport.service' ;
65import logger from '../logger' ;
76import { PilotDocument } from '../pilot/pilot.model' ;
87import { PilotService } from '../pilot/pilot.service' ;
9- import { AGENDA_PROVIDER } from '../schedule.module ' ;
8+ import { Schedule } from '../schedule/schedule.decorator ' ;
109import { UtilsService } from '../utils/utils.service' ;
1110
1211import { AirportCapacity } from '@/shared/interfaces/airport.interface' ;
@@ -16,18 +15,13 @@ interface IBlockAssignment {
1615 ttot : Date ;
1716}
1817
19- const jobNameOptimizeBlockAssignments = 'CDM_optimizeBlockAssignments' ;
20-
2118@Injectable ( )
2219export class CdmService {
2320 constructor (
2421 @Inject ( forwardRef ( ( ) => AirportService ) ) private airportService : AirportService ,
2522 @Inject ( forwardRef ( ( ) => PilotService ) ) private pilotService : PilotService ,
2623 private utilsService : UtilsService ,
27- @Inject ( AGENDA_PROVIDER ) private agenda : Agenda ,
2824 ) {
29- this . agenda . define ( jobNameOptimizeBlockAssignments , this . optimizeBlockAssignments . bind ( this ) ) ;
30- this . agenda . every ( '2 minute' , jobNameOptimizeBlockAssignments ) ;
3125 }
3226
3327 determineInitialBlock ( pilot : PilotDocument ) : IBlockAssignment {
@@ -154,6 +148,7 @@ export class CdmService {
154148 return this . putPilotIntoBlock ( pilot , allPilots ) ;
155149 }
156150
151+ @Schedule ( )
157152 private async optimizeBlockAssignments ( ) : Promise < void > {
158153 const currentBlockId = this . utilsService . getBlockFromTime ( new Date ( ) ) ;
159154 const allAirports = await this . airportService . getAllAirports ( ) ;
0 commit comments