Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry more slowly but for longer (every 30s up to 2hrs) [MARXAN-1771] #1247

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type ApiEventSelectResult = {

type FeatureIdByIntegerId = Record<number, string>;

export const retriesIntervalForSpecificationStatusInSeconds = 30;

@Injectable()
@LegacyProjectImportPieceProcessorProvider()
export class FeaturesSpecificationLegacyProjectPieceImporter
Expand Down Expand Up @@ -246,11 +248,11 @@ export class FeaturesSpecificationLegacyProjectPieceImporter

private async waitUntilSpecificationEnds(
scenarioId: string,
retries = 20,
retries = 240,
): Promise<Either<string, true>> {
const timeout = left('specification timeout');
const failure = left('specification failed');
const intervalSeconds = 3;
const intervalSeconds = retriesIntervalForSpecificationStatusInSeconds;
let triesLeft = retries;

return new Promise<Either<string, true>>((resolve) => {
Expand Down Expand Up @@ -289,6 +291,7 @@ export class FeaturesSpecificationLegacyProjectPieceImporter
specRows: PropSpecDatRow[],
projectId: string,
scenarioId: string,
retries?: number,
): Promise<void> {
const featureIdByIntegerId = await this.getFeatureIdByIntegerIdMap(
projectId,
Expand Down Expand Up @@ -328,6 +331,7 @@ export class FeaturesSpecificationLegacyProjectPieceImporter

const specificationResult = await this.waitUntilSpecificationEnds(
scenarioId,
retries
);
if (isLeft(specificationResult)) {
this.logAndThrow(
Expand Down Expand Up @@ -393,6 +397,7 @@ export class FeaturesSpecificationLegacyProjectPieceImporter

async run(
input: LegacyProjectImportJobInput,
retries?: number,
): Promise<LegacyProjectImportJobOutput> {
const { files, projectId, scenarioId } = input;

Expand All @@ -413,7 +418,7 @@ export class FeaturesSpecificationLegacyProjectPieceImporter
}

const specRows = this.getPropSpecRows(specRowsOrError, puvsprRowsOrError);
await this.runSpecification(specRows, projectId, scenarioId);
await this.runSpecification(specRows, projectId, scenarioId, retries);
await this.updateScenarioFeaturesData(specRows, scenarioId);

return input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { Either, isLeft, left, right } from 'fp-ts/lib/Either';
import { Readable } from 'stream';
import { EntityManager, In, Repository } from 'typeorm';
import { v4 } from 'uuid';
import { FeaturesSpecificationLegacyProjectPieceImporter } from '../../../src/legacy-project-import/legacy-piece-importers/features-specification.legacy-piece-importer';
import { FeaturesSpecificationLegacyProjectPieceImporter, retriesIntervalForSpecificationStatusInSeconds } from '../../../src/legacy-project-import/legacy-piece-importers/features-specification.legacy-piece-importer';
import {
specDatFeatureIdPropertyKey,
specDatPuidPropertyKey,
Expand All @@ -54,6 +54,9 @@ import {
} from '../cloning/fixtures';

let fixtures: FixtureType<typeof getFixtures>;
// needs to be comfortably > than the retries interval when polling for
// status
const timeoutForTestsThatNeedToCheckSpecificationJobStatus = 2 * retriesIntervalForSpecificationStatusInSeconds * 1000;

describe(FeaturesSpecificationLegacyProjectPieceImporter, () => {
beforeEach(async () => {
Expand Down Expand Up @@ -224,9 +227,9 @@ describe(FeaturesSpecificationLegacyProjectPieceImporter, () => {
.WhenPieceImporterIsInvoked(job)
.AndSpecificationProcessFails()
.ThenASpecificationDidntFinishErrorShouldBeThrown();
});
}, timeoutForTestsThatNeedToCheckSpecificationJobStatus);

it(`fails when specification async job timeouts`, async () => {
it(`fails when specification async job times out`, async () => {
const specDatFileType = LegacyProjectImportFileType.SpecDat;
const puvsprDatFileType = LegacyProjectImportFileType.PuvsprDat;

Expand All @@ -245,10 +248,10 @@ describe(FeaturesSpecificationLegacyProjectPieceImporter, () => {
fixtures.GivenValidPuvsprDatFile();

await fixtures
.WhenPieceImporterIsInvoked(job)
.AndSpecificationProcessTimeouts()
.WhenPieceImporterIsInvoked(job, 2)
.AndSpecificationProcessTimesOut()
.ThenASpecificationDidntFinishErrorShouldBeThrown();
}, 70_000);
}, timeoutForTestsThatNeedToCheckSpecificationJobStatus * 2);

it(`fails if features data records does not contain required properties`, async () => {
const specDatFileType = LegacyProjectImportFileType.SpecDat;
Expand All @@ -275,7 +278,7 @@ describe(FeaturesSpecificationLegacyProjectPieceImporter, () => {
.WhenPieceImporterIsInvoked(job)
.AndSpecificationProcessSucceeds()
.ThenAMissingRequiredPropertiesErrorShouldBeThrown();
});
}, timeoutForTestsThatNeedToCheckSpecificationJobStatus);

it('fails if puvspr.dat contains features not present in spec.dat', async () => {
const specDatFileType = LegacyProjectImportFileType.SpecDat;
Expand Down Expand Up @@ -329,7 +332,7 @@ describe(FeaturesSpecificationLegacyProjectPieceImporter, () => {
.WhenPieceImporterIsInvoked(job)
.AndSpecificationProcessSucceeds()
.ThenScenarioFeaturesDataShouldBeImported();
});
}, timeoutForTestsThatNeedToCheckSpecificationJobStatus);
});

const getFixtures = async () => {
Expand Down Expand Up @@ -682,7 +685,7 @@ const getFixtures = async () => {
}),
);
},
WhenPieceImporterIsInvoked: (input: LegacyProjectImportJobInput) => {
WhenPieceImporterIsInvoked: (input: LegacyProjectImportJobInput, retries?: number) => {
return {
ThenADatFileNotFoundErrorShouldBeThrown: async (
file: LegacyProjectImportFileType,
Expand Down Expand Up @@ -729,10 +732,10 @@ const getFixtures = async () => {
},
};
},
AndSpecificationProcessTimeouts: () => {
AndSpecificationProcessTimesOut: () => {
return {
ThenASpecificationDidntFinishErrorShouldBeThrown: async () => {
await expect(sut.run(input)).rejects.toThrow(
await expect(sut.run(input, retries)).rejects.toThrow(
/specification didn't finish: specification timeout/gi,
);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LegacyProjectImportPiece } from './domain/legacy-project-import-piece';

export abstract class LegacyProjectImportPieceProcessor<I, O> {
abstract run(input: I): Promise<O>;
abstract run(input: I, retries?: number): Promise<O>;

abstract isSupported(piece: LegacyProjectImportPiece): boolean;
}