Skip to content

Commit

Permalink
fix: add mechanism to force resync if cannot read data stored in fs
Browse files Browse the repository at this point in the history
  • Loading branch information
f1ames committed Feb 8, 2024
1 parent ce0fe91 commit be5334a
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions packages/synchronizer/src/utils/projectSynchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ export class ProjectSynchronizer extends EventEmitter {
);
}

let resyncDueToError = false;
let existingSuppressions: ApiSuppression[] = [];
let existingPolicy = {};
try {
existingSuppressions = await this.readSuppressions(repoData);
existingPolicy = await this.readPolicy(repoData) ?? {}
} catch (err) {
resyncDueToError = true;
}

if (resyncDueToError) {
await this.dropCacheMetadata(repoData);
}

const projectValidationData = await this.refetchProjectValidationData(
repoData,
projectDetails.data.getProject.projectRepository.id,
Expand All @@ -156,7 +170,6 @@ export class ProjectSynchronizer extends EventEmitter {
tokenInfo
);

const existingSuppressions = await this.readSuppressions(repoData);
const dataCache: ProjectDataCache = {
project: {
id: projectDetails.data.getProject.id,
Expand All @@ -166,7 +179,7 @@ export class ProjectSynchronizer extends EventEmitter {
permissions: projectDetails.data.getProject.permissions,
repository: projectDetails.data.getProject.projectRepository,
suppressions: existingSuppressions,
policy: {}
policy: existingPolicy
};

if (projectValidationData.suppressions.length) {
Expand All @@ -189,8 +202,6 @@ export class ProjectSynchronizer extends EventEmitter {
}

dataCache.policy = projectValidationData.policy.json;
} else {
dataCache.policy = await this.readPolicy(repoData) ?? {};
}

this._dataCache[cacheId] = dataCache;
Expand Down Expand Up @@ -328,7 +339,11 @@ export class ProjectSynchronizer extends EventEmitter {
}

private async readCacheMetadata(repoData: RepoRemoteInputData) {
return (await this._storageHandlerJsonCache.getStoreData(this.getMetadataFileName(repoData)) ?? {}) as CacheMetadata;
try {
return (await this._storageHandlerJsonCache.getStoreData(this.getMetadataFileName(repoData)) ?? {}) as CacheMetadata;
} catch (err) {
return {} as CacheMetadata;
}
}

private async dropCacheMetadata(repoData: RepoRemoteInputData) {
Expand Down

0 comments on commit be5334a

Please sign in to comment.