Added loadOfffer with retry

This commit is contained in:
Srinath Narayanan
2020-11-11 08:46:28 -08:00
parent a133134b8b
commit 6d94f18f9a
4 changed files with 28 additions and 3 deletions

View File

@@ -437,3 +437,8 @@ export class TerminalQueryParams {
public static readonly SubscriptionId = "subscriptionId";
public static readonly TerminalEndpoint = "terminalEndpoint";
}
export class LoadOfferRetry {
public static readonly MaxRetries = 5;
public static readonly RetryAfterMilliSeconds = 5000;
}

View File

@@ -162,6 +162,7 @@ export interface Collection extends CollectionBase {
loadStoredProcedures(): Promise<any>;
loadTriggers(): Promise<any>;
loadOffer(): Promise<void>;
loadAutopilotOfferWithRetry(): Promise<DataModels.Offer>;
createStoredProcedureNode(data: StoredProcedureDefinition & Resource): StoredProcedure;
createUserDefinedFunctionNode(data: UserDefinedFunctionDefinition & Resource): UserDefinedFunction;

View File

@@ -532,11 +532,12 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
}
const updatedOffer: DataModels.Offer = await updateOffer(updateOfferParams);
this.collection.offer(updatedOffer);
this.setState({ isScaleSaveable: false, isScaleDiscardable: false });
if (this.state.isAutoPilotSelected) {
const autoPilotOffer = await this.collection.loadAutopilotOfferWithRetry();
this.setState({
autoPilotThroughput: updatedOffer.content.offerAutopilotSettings.maxThroughput,
autoPilotThroughputBaseline: updatedOffer.content.offerAutopilotSettings.maxThroughput
autoPilotThroughput: autoPilotOffer.content.offerAutopilotSettings.maxThroughput,
autoPilotThroughputBaseline: autoPilotOffer.content.offerAutopilotSettings.maxThroughput
});
} else {
this.setState({
@@ -544,6 +545,8 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
throughputBaseline: updatedOffer.content.offerThroughput
});
}
this.setState({ isScaleSaveable: false, isScaleDiscardable: false });
}
}
this.container.isRefreshingExplorer(false);

View File

@@ -1331,6 +1331,22 @@ export default class Collection implements ViewModels.Collection {
return this.container.findDatabaseWithId(this.databaseId);
}
public async loadAutopilotOfferWithRetry(): Promise<DataModels.Offer> {
let retryCount = 0;
while (retryCount < Constants.LoadOfferRetry.MaxRetries) {
if (this.offer().content.offerAutopilotSettings) {
return this.offer();
} else {
await new Promise(resolve => setTimeout(resolve, Constants.LoadOfferRetry.RetryAfterMilliSeconds));
await this.loadOffer();
}
retryCount++;
}
throw new Error(
"Max Retries for loading offer are completed. Offer does not have an offerAutopilotSettings field."
);
}
public async loadOffer(): Promise<void> {
if (!this.container.isServerlessEnabled() && !this.offer()) {
this.container.isRefreshingExplorer(true);