Skip to content

Commit 99f9f13

Browse files
author
unknown
committed
Use backoff delay for New-AzureRmResourceGroupDeployment query calls
1 parent 24eebc9 commit 99f9f13

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

src/Common/Commands.Common/TestMockSupport.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,37 @@ public static void Delay(TimeSpan duration)
4747
}
4848
}
4949
}
50+
51+
public class Delay
52+
{
53+
public const int DefaultMaxDelayInMilliseconds = 60000;
54+
55+
public const int DefaultBackoffStepInMilliseconds = 5000;
56+
57+
public const int DefaultDelayInMilliseconds = 0;
58+
59+
private int backoffStep;
60+
61+
private int maxDelay;
62+
63+
private int nextDelay;
64+
65+
public Delay(int backoffStep = DefaultBackoffStepInMilliseconds, int firstDelay = DefaultDelayInMilliseconds, int maxDelay = DefaultMaxDelayInMilliseconds)
66+
{
67+
this.backoffStep = backoffStep;
68+
this.maxDelay = maxDelay;
69+
70+
this.nextDelay = firstDelay;
71+
}
72+
73+
public int GetNextDelay()
74+
{
75+
int delay = this.nextDelay;
76+
77+
this.nextDelay += this.backoffStep;
78+
this.nextDelay = Math.Min(maxDelay, this.nextDelay);
79+
80+
return delay;
81+
}
82+
}
5083
}

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Resource/NewAzureResourceCmdlet.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ public sealed class NewAzureResourceCmdlet : ResourceManipulationCmdletBase
6363
/// <summary>
6464
/// Gets or sets the plan object.
6565
/// </summary>
66+
[Alias("SkuObject")]
6667
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "A hash table which represents sku properties.")]
6768
[ValidateNotNullOrEmpty]
68-
public Hashtable SkuObject { get; set; }
69+
public Hashtable Sku { get; set; }
6970

7071

7172
/// <summary>
@@ -142,7 +143,7 @@ private Resource<JToken> GetResource()
142143
Location = this.Location,
143144
Kind = this.Kind,
144145
Plan = this.PlanObject.ToDictionary(addValueLayer: false).ToJson().FromJson<ResourcePlan>(),
145-
Sku = this.SkuObject.ToDictionary(addValueLayer: false).ToJson().FromJson<ResourceSku>(),
146+
Sku = this.Sku.ToDictionary(addValueLayer: false).ToJson().FromJson<ResourceSku>(),
146147
Tags = TagsHelper.GetTagsDictionary(this.Tag),
147148
Properties = this.Properties.ToResourcePropertiesBody(),
148149
};

src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,18 @@ private DeploymentExtended WaitDeploymentStatus(
325325
params string[] status)
326326
{
327327
DeploymentExtended deployment;
328+
Delay stepedDelay = new Delay(firstDelay: 0);
328329

329330
do
330331
{
332+
TestMockSupport.Delay(stepedDelay.GetNextDelay());
333+
331334
if (job != null)
332335
{
333336
job(resourceGroup, deploymentName, basicDeployment);
334337
}
335-
338+
336339
deployment = ResourceManagementClient.Deployments.Get(resourceGroup, deploymentName).Deployment;
337-
TestMockSupport.Delay(10000);
338340

339341
} while (!status.Any(s => s.Equals(deployment.Properties.ProvisioningState, StringComparison.OrdinalIgnoreCase)));
340342

0 commit comments

Comments
 (0)