forked from Azure/azure-functions-host
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to retry function execution on invocation failures (Azure…
- Loading branch information
1 parent
3a68115
commit dd062a5
Showing
22 changed files
with
413 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
sample/NodeRetry/HttpTrigger-RetryFunctionJson/function.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req", | ||
"methods": [ | ||
"get", | ||
"post" | ||
] | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "res" | ||
} | ||
], | ||
"retry": { | ||
"strategy": "fixedDelay", | ||
"maxRetryCount": 4, | ||
"delayInterval": "00:00:03" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var invocationCount = 0; | ||
|
||
module.exports = async function (context, req) { | ||
const reset = req.query.reset; | ||
invocationCount = reset ? 0 : invocationCount | ||
|
||
context.log('JavaScript HTTP trigger function processed a request.invocationCount: ' + invocationCount); | ||
|
||
invocationCount = invocationCount + 1; | ||
const responseMessage = "invocationCount: " + invocationCount; | ||
if (invocationCount < 4) { | ||
throw new Error('An error occurred'); | ||
} | ||
context.res = { | ||
// status: 200, /* Defaults to 200 */ | ||
body: responseMessage | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req", | ||
"methods": [ | ||
"get", | ||
"post" | ||
] | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "res" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var invocationCount = 0; | ||
|
||
module.exports = async function (context, req) { | ||
const reset = req.query.reset; | ||
invocationCount = reset ? 0 : invocationCount | ||
|
||
context.log('JavaScript HTTP trigger function processed a request.invocationCount: ' + invocationCount); | ||
|
||
invocationCount = invocationCount + 1; | ||
const responseMessage = "invocationCount: " + invocationCount; | ||
if (invocationCount < 2) { | ||
throw new Error('An error occurred'); | ||
} | ||
context.res = { | ||
// status: 200, /* Defaults to 200 */ | ||
body: responseMessage | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"version": "2.0", | ||
"retry": { | ||
"strategy": "fixedDelay", | ||
"maxRetryCount": 2, | ||
"delayInterval": "00:00:03" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using Microsoft.Azure.WebJobs.Host; | ||
using Microsoft.Azure.WebJobs.Script.Description; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script | ||
{ | ||
internal static class CustomAttributeBuilderUtility | ||
{ | ||
internal static CustomAttributeBuilder GetRetryCustomAttributeBuilder(RetryOptions functionRetry) | ||
{ | ||
switch (functionRetry.Strategy) | ||
{ | ||
case RetryStrategy.FixedDelay: | ||
Type fixedDelayRetryType = typeof(FixedDelayRetryAttribute); | ||
ConstructorInfo fixedDelayRetryCtorInfo = fixedDelayRetryType.GetConstructor(new[] { typeof(int), typeof(string) }); | ||
CustomAttributeBuilder fixedDelayRetryBuilder = new CustomAttributeBuilder( | ||
fixedDelayRetryCtorInfo, | ||
new object[] { functionRetry.MaxRetryCount, functionRetry.DelayInterval.ToString() }); | ||
return fixedDelayRetryBuilder; | ||
case RetryStrategy.ExponentialBackoff: | ||
Type exponentialBackoffRetryType = typeof(ExponentialBackoffRetryAttribute); | ||
ConstructorInfo exponentialBackoffDelayRetryCtorInfo = exponentialBackoffRetryType.GetConstructor(new[] { typeof(int), typeof(string), typeof(string) }); | ||
CustomAttributeBuilder exponentialBackoffRetryBuilder = new CustomAttributeBuilder( | ||
exponentialBackoffDelayRetryCtorInfo, | ||
new object[] { functionRetry.MaxRetryCount, functionRetry.MinimumInterval.ToString(), functionRetry.MaximumInterval.ToString() }); | ||
return exponentialBackoffRetryBuilder; | ||
} | ||
return null; | ||
} | ||
|
||
internal static CustomAttributeBuilder GetTimeoutCustomAttributeBuilder(TimeSpan functionTimeout) | ||
{ | ||
Type timeoutType = typeof(TimeoutAttribute); | ||
ConstructorInfo ctorInfo = timeoutType.GetConstructor(new[] { typeof(string) }); | ||
|
||
PropertyInfo[] propertyInfos = new[] | ||
{ | ||
timeoutType.GetProperty("ThrowOnTimeout"), | ||
timeoutType.GetProperty("TimeoutWhileDebugging") | ||
}; | ||
|
||
// Hard-code these for now. Eventually elevate to config | ||
object[] propertyValues = new object[] | ||
{ | ||
true, | ||
true | ||
}; | ||
|
||
return new CustomAttributeBuilder( | ||
ctorInfo, | ||
new object[] { functionTimeout.ToString() }, | ||
propertyInfos, | ||
propertyValues); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.