in packages/service-library/src/batch/batch-task-creator.ts [45:82]
public async run(): Promise<void> {
if (!this.hasInitialized) {
throw new Error('The BatchTaskCreator instance is not initialized.');
}
this.activeScanMessages = [];
const restartAfterTime = moment().add(this.jobManagerConfig.maxWallClockTimeInMinutes, 'minutes').toDate();
// eslint-disable-next-line no-constant-condition
while (true) {
const messages = await this.getMessagesForTaskCreation();
if (messages.length === 0 && (await this.getJobPendingTasksCount()) === 0) {
this.logger.logInfo(`All tasks are completed and no new scan requests available. Exiting the job manager.`);
break;
} else if (messages.length > 0) {
this.activeScanMessages.push(...messages);
const jobTasks = await this.addTasksToJob(messages);
await this.onTasksAdded(jobTasks);
}
if (moment().toDate() >= restartAfterTime) {
this.logger.logInfo(
`Performing scheduled job manager termination after ${this.jobManagerConfig.maxWallClockTimeInMinutes} minutes.`,
);
break;
}
await this.system.wait(this.jobManagerConfig.addTasksIntervalInSeconds * 1000);
await this.validateTasks();
}
await this.waitForChildTasks();
await this.validateTasks();
await this.onExit();
}