Skip to content

Commit 2094e59

Browse files
authored
fix: retry on net errors when retrieving MD info (#941)
* fix: retry on net errors when retrieving MD info * fix: do not ignore polling client err
1 parent ca499ac commit 2094e59

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/resolve/connectionResolver.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

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

101+
const pollingOptions: PollingClient.Options = {
102+
frequency: Duration.milliseconds(1000),
103+
timeout: Duration.minutes(3),
104+
poll: async (): Promise<StatusResult> => {
105+
const res = ensureArray(await this.connection.metadata.list(query));
106+
return { completed: true, payload: res };
107+
},
108+
};
109+
110+
const pollingClient = await PollingClient.create(pollingOptions);
111+
101112
try {
102-
members = ensureArray((await this.connection.metadata.list(query)) as FileProperties[]);
113+
members = await pollingClient.subscribe();
103114
} catch (error) {
115+
// throw error if PollingClient timed out.
116+
if (error instanceof NotRetryableError) {
117+
throw NotRetryableError;
118+
}
104119
this.logger.debug((error as Error).message);
105120
members = [];
106121
}

0 commit comments

Comments
 (0)