use the new logging module
This commit is contained in:
@@ -3,6 +3,7 @@ import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { PerformanceSchema } from './models/performance.model';
|
||||
import { PerformanceService } from './performance.service';
|
||||
import { VersioningModule } from '../versioning/versioning.module';
|
||||
import { LoggingModule } from 'src/logging/logging.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -10,6 +11,7 @@ import { VersioningModule } from '../versioning/versioning.module';
|
||||
{ name: 'performance', schema: PerformanceSchema },
|
||||
]),
|
||||
VersioningModule,
|
||||
LoggingModule,
|
||||
],
|
||||
providers: [PerformanceService],
|
||||
exports: [MongooseModule, PerformanceService],
|
||||
|
||||
@@ -6,10 +6,17 @@ import { Model } from 'mongoose';
|
||||
import { join } from 'path';
|
||||
import { SemanticVersionDto } from 'src/versioning/dto/semanticversion.dto';
|
||||
import { VersioningService } from '../versioning/versioning.service';
|
||||
import { LoggingService } from 'src/logging/logging.service';
|
||||
import { PerformanceDocument } from './models/performance.model';
|
||||
|
||||
const COMPONENT_NAME = 'performance';
|
||||
|
||||
enum UpdateReturnCodes {
|
||||
Updated,
|
||||
Ignored,
|
||||
Failure,
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class PerformanceService {
|
||||
private static readPerformanceFile(): Record<string, any> {
|
||||
@@ -69,11 +76,35 @@ export class PerformanceService {
|
||||
});
|
||||
}
|
||||
|
||||
private async validateAndUpdatePerformanceData(): Promise<string[]> {
|
||||
private async validateAndUpdatePerformanceData(): Promise<{
|
||||
status: UpdateReturnCodes;
|
||||
ignored: string[];
|
||||
}> {
|
||||
// read the performance file and validate the version length
|
||||
const data = PerformanceService.readPerformanceFile();
|
||||
if (data['FILEINFO'] === undefined) {
|
||||
this.loggingService.addInfoMessage(
|
||||
COMPONENT_NAME,
|
||||
`The fileinfo block is missing`,
|
||||
);
|
||||
return { status: UpdateReturnCodes.Failure, ignored: [] };
|
||||
}
|
||||
if (data['FILEINFO']['createdAt'] === undefined) {
|
||||
this.loggingService.addInfoMessage(
|
||||
COMPONENT_NAME,
|
||||
`The createdAt of the fileinfo block is missing`,
|
||||
);
|
||||
return { status: UpdateReturnCodes.Failure, ignored: [] };
|
||||
}
|
||||
|
||||
const versionParts = (data['FILEINFO']['version'] as string).split('.');
|
||||
if (versionParts.length !== 3) return [];
|
||||
if (versionParts.length !== 3) {
|
||||
this.loggingService.addInfoMessage(
|
||||
COMPONENT_NAME,
|
||||
`The version of fileinfo is missing or wrong: ${data['FILEINFO']['version']}. Expected: x.y.z`,
|
||||
);
|
||||
return { status: UpdateReturnCodes.Failure, ignored: [] };
|
||||
}
|
||||
|
||||
// create the fileversion
|
||||
const fileversion: SemanticVersionDto = {
|
||||
@@ -84,7 +115,7 @@ export class PerformanceService {
|
||||
|
||||
return this.versioningService
|
||||
.findComponent(COMPONENT_NAME)
|
||||
.then((resp) => {
|
||||
.then(async (resp) => {
|
||||
if (
|
||||
resp === null ||
|
||||
VersioningService.newerVersion(
|
||||
@@ -96,19 +127,45 @@ export class PerformanceService {
|
||||
fileversion,
|
||||
)
|
||||
) {
|
||||
return this.updatePerformanceData(data, fileversion);
|
||||
return {
|
||||
status: UpdateReturnCodes.Updated,
|
||||
ignored: await this.updatePerformanceData(data, fileversion),
|
||||
};
|
||||
}
|
||||
|
||||
return [];
|
||||
return { status: UpdateReturnCodes.Ignored, ignored: [] };
|
||||
})
|
||||
.catch(() => this.updatePerformanceData(data, fileversion));
|
||||
.catch(async () => ({
|
||||
status: UpdateReturnCodes.Updated,
|
||||
ignored: await this.updatePerformanceData(data, fileversion),
|
||||
}));
|
||||
}
|
||||
|
||||
constructor(
|
||||
@InjectModel('performance')
|
||||
private readonly performanceModel: Model<PerformanceDocument>,
|
||||
private readonly versioningService: VersioningService,
|
||||
private readonly loggingService: LoggingService,
|
||||
) {
|
||||
this.validateAndUpdatePerformanceData();
|
||||
this.validateAndUpdatePerformanceData().then(async (response) => {
|
||||
response.ignored.forEach(async (entry) => {
|
||||
await this.loggingService.addInfoMessage(
|
||||
COMPONENT_NAME,
|
||||
`Ignored ${entry}. Required entries: speedabovefl240, rodabovefl240, speedabovefl100, rodabovefl100, speedbelowfl100, rodbelowfl100, speedapproach`,
|
||||
);
|
||||
});
|
||||
|
||||
if (response.status === UpdateReturnCodes.Ignored) {
|
||||
await this.loggingService.addInfoMessage(
|
||||
COMPONENT_NAME,
|
||||
`Ignored the performance file due to the file version`,
|
||||
);
|
||||
} else if (response.status === UpdateReturnCodes.Failure) {
|
||||
await this.loggingService.addInfoMessage(
|
||||
COMPONENT_NAME,
|
||||
`Wasn't able to update the performance database`,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user