Skip to content

Commit

Permalink
fix: retry on net errors when retrieving MD info (#941)
Browse files Browse the repository at this point in the history
* fix: retry on net errors when retrieving MD info

* fix: do not ignore polling client err
  • Loading branch information
cristiand391 authored Apr 19, 2023
1 parent ca499ac commit 2094e59
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/resolve/connectionResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { Connection, Logger } from '@salesforce/core';
import { ensureArray } from '@salesforce/kit';
import { PollingClient, StatusResult, Connection, Logger } from '@salesforce/core';
import { Duration, ensureArray } from '@salesforce/kit';
import { retry, NotRetryableError, RetryError } from 'ts-retry-promise';
import { ensurePlainObject, ensureString, isPlainObject } from '@salesforce/ts-types';
import { RegistryAccess, registry as defaultRegistry, MetadataType } from '../registry';
Expand Down Expand Up @@ -98,9 +98,24 @@ export class ConnectionResolver {
private async listMembers(query: ListMetadataQuery): Promise<FileProperties[]> {
let members: FileProperties[];

const pollingOptions: PollingClient.Options = {
frequency: Duration.milliseconds(1000),
timeout: Duration.minutes(3),
poll: async (): Promise<StatusResult> => {
const res = ensureArray(await this.connection.metadata.list(query));
return { completed: true, payload: res };
},
};

const pollingClient = await PollingClient.create(pollingOptions);

try {
members = ensureArray((await this.connection.metadata.list(query)) as FileProperties[]);
members = await pollingClient.subscribe();
} catch (error) {
// throw error if PollingClient timed out.
if (error instanceof NotRetryableError) {
throw NotRetryableError;
}
this.logger.debug((error as Error).message);
members = [];
}
Expand Down

0 comments on commit 2094e59

Please sign in to comment.