Skip to content

update record clean up retries to the collection #103

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -45,7 +45,7 @@
</Target>

<ItemGroup>
<PackageReference Include="Dynamics365.UIAutomation.Api" Version="9.2.21014.138" />
<PackageReference Include="Dynamics365.UIAutomation.Api" Version="9.2.21084.148" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.Build.Tasks.Git" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
27 changes: 15 additions & 12 deletions driver/src/data/dataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,31 @@ export default class DataManager {
* @returns {Promise<void>}
* @memberof DataManager
*/

public async cleanup(): Promise<(Xrm.LookupValue | void)[]> {
const repo = this.appUserRecordRepo || this.currentUserRecordRepo;

const deletePromises = this.refs.map(async (record) => {
let reference;
let retry = 0;
while (retry < 3) {
let passThrough = 0;
let deletePromises: (Xrm.LookupValue | void)[] = [];
while (passThrough < 3 && this.refs.length > 0) {
// eslint-disable-next-line no-await-in-loop
deletePromises = await Promise.all(this.refs.map(async (record) => {
let reference;
try {
// eslint-disable-next-line no-await-in-loop
reference = await repo.deleteRecord(record);
break;
const i = this.refs.indexOf(record);
this.refs.splice(i, 1);
} catch (err) {
retry += 1;
// TODO: Log records failed to be deleted after finale passthrough
}
}
return reference;
});
return reference;
}));
passThrough += 1;
}

this.refs.splice(0, this.refs.length);
Object.keys(this.refsByAlias).forEach((alias) => delete this.refsByAlias[alias]);

return Promise.all(deletePromises);
return deletePromises;
}

private preprocess(data: Record): Record {
Expand Down
2 changes: 1 addition & 1 deletion driver/test/data/dataManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('TestDriver', () => {
it('retries failed delete requests', async () => {
appUserRecordRepo.deleteRecord.and.throwError('Failed to delete');

dataManager.cleanup();
await dataManager.cleanup();

expect(appUserRecordRepo.deleteRecord.calls.count()).toBe(6);
});
Expand Down