Skip to content

Commit 15c7e54

Browse files
update
1 parent c15cf1b commit 15c7e54

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/AzureAppConfigurationImpl.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ type PagedSettingSelector = SettingSelector & {
5050
};
5151

5252
const DEFAULT_STARTUP_TIMEOUT = 100 * 1000; // 100 seconds in milliseconds
53-
const MAX_STARTUP_TIMEOUT = 60 * 60 * 1000; // 60 minutes in milliseconds
5453

5554
export class AzureAppConfigurationImpl implements AzureAppConfiguration {
5655
/**
@@ -335,8 +334,9 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
335334
async #initialize() {
336335
if (!this.#isInitialLoadCompleted) {
337336
await this.#inspectFmPackage();
337+
const retryEnabled = this.#options?.startupOptions?.retryEnabled ?? false;
338338
const startTimestamp = Date.now();
339-
while (startTimestamp + MAX_STARTUP_TIMEOUT > Date.now()) {
339+
while (true) {
340340
try {
341341
await this.#loadSelectedAndWatchedKeyValues();
342342
if (this.#featureFlagEnabled) {
@@ -346,20 +346,21 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
346346
this.#isInitialLoadCompleted = true;
347347
break;
348348
} catch (error) {
349-
const timeElapsed = Date.now() - startTimestamp;
350-
let postAttempts = 0;
351-
let backoffDuration = getFixedBackoffDuration(timeElapsed);
352-
if (backoffDuration === undefined) {
353-
postAttempts += 1;
354-
backoffDuration = calculateDynamicBackoffDuration(postAttempts);
349+
if (retryEnabled) {
350+
const timeElapsed = Date.now() - startTimestamp;
351+
let postAttempts = 0;
352+
let backoffDuration = getFixedBackoffDuration(timeElapsed);
353+
if (backoffDuration === undefined) {
354+
postAttempts += 1;
355+
backoffDuration = calculateDynamicBackoffDuration(postAttempts);
356+
}
357+
await new Promise(resolve => setTimeout(resolve, backoffDuration));
358+
console.warn("Failed to load configuration settings at startup. Retrying...");
359+
} else {
360+
throw error;
355361
}
356-
await new Promise(resolve => setTimeout(resolve, backoffDuration));
357-
console.warn("Failed to load configuration settings at startup. Retrying...");
358362
}
359363
}
360-
if (!this.#isInitialLoadCompleted) {
361-
throw new Error("Load operation exceeded the maximum startup timeout.");
362-
}
363364
}
364365
}
365366

src/StartupOptions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
// Licensed under the MIT license.
33

44
export interface StartupOptions {
5+
/**
6+
* Specifies whether to enable retry on startup or not.
7+
*
8+
* @remarks
9+
* If not specified, the default value is false.
10+
*/
11+
retryEnabled?: boolean;
12+
513
/**
614
* The amount of time allowed to load data from Azure App Configuration on startup.
715
*

0 commit comments

Comments
 (0)