|
5 | 5 | * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause |
6 | 6 | */ |
7 | 7 |
|
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'; |
10 | 10 | import { retry, NotRetryableError, RetryError } from 'ts-retry-promise'; |
11 | 11 | import { ensurePlainObject, ensureString, isPlainObject } from '@salesforce/ts-types'; |
12 | 12 | import { RegistryAccess, registry as defaultRegistry, MetadataType } from '../registry'; |
@@ -98,9 +98,24 @@ export class ConnectionResolver { |
98 | 98 | private async listMembers(query: ListMetadataQuery): Promise<FileProperties[]> { |
99 | 99 | let members: FileProperties[]; |
100 | 100 |
|
| 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 | + |
101 | 112 | try { |
102 | | - members = ensureArray((await this.connection.metadata.list(query)) as FileProperties[]); |
| 113 | + members = await pollingClient.subscribe(); |
103 | 114 | } catch (error) { |
| 115 | + // throw error if PollingClient timed out. |
| 116 | + if (error instanceof NotRetryableError) { |
| 117 | + throw NotRetryableError; |
| 118 | + } |
104 | 119 | this.logger.debug((error as Error).message); |
105 | 120 | members = []; |
106 | 121 | } |
|
0 commit comments