Skip to content

Commit

Permalink
Revert "Updating Microsoft.Azure.WebJobs to 3.0.33-11924 (Azure#8324)"
Browse files Browse the repository at this point in the history
This reverts commit c7535d6.
  • Loading branch information
alrod committed May 16, 2022
1 parent c550f97 commit e4b2e5e
Show file tree
Hide file tree
Showing 20 changed files with 192 additions and 130 deletions.
7 changes: 1 addition & 6 deletions sample/CustomHandlerRetry/HttpTrigger/function.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,5 @@
"direction": "out",
"name": "res"
}
],
"retry": {
"strategy": "fixedDelay",
"maxRetryCount": 2,
"delayInterval": "00:00:00"
}
]
}
16 changes: 0 additions & 16 deletions sample/CustomHandlerRetry/TimerTrigger/function.json

This file was deleted.

5 changes: 5 additions & 0 deletions sample/CustomHandlerRetry/host.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
"defaultExecutablePath": "node",
"arguments": [ "server.js" ]
}
},
"retry": {
"strategy": "fixedDelay",
"maxRetryCount": 2,
"delayInterval": "00:00:00"
}
}
44 changes: 13 additions & 31 deletions sample/CustomHandlerRetry/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,27 @@ app.use(

app.use(express.json())

var response = {
"Outputs": {
"res": {
"body": "OK"
}
},
"Logs": null,
"ReturnValue": null
}

count = 0;
app.post('/HttpTrigger', (req, res) => {
if (req.body.Metadata.RetryContext) {
let retryCount = req.body.Metadata.RetryContext.RetryCount;
let maxRetry = req.body.Metadata.RetryContext.MaxRetryCount;
var response = {
"Outputs": {
"res": {
"body": "Retry Count:" + retryCount + " Max Retry Count:" + maxRetry
}
},
"Logs": null,
"ReturnValue": null
}
if (retryCount < maxRetry) {
res.status(500).send(response)
}
else {
res.status(200).send(response)
}
})

app.post('/TimerTrigger', (req, res) => {
var errorString = 'An error occurred';
var maxRetries = 4;
var retryContext = req.body.Metadata.RetryContext;

if (retryContext.MaxRetryCount != maxRetries) {
console.log('Unexpected error');
throw 'Unexpected error';
} else {
console.log('JavaScript HTTP trigger function processed a request. retryCount: ' + retryContext.RetryCount);

if (retryContext.RetryCount < maxRetries) {
console.log(errorString);
throw errorString;
}
console.log('Execution completed');
res.status(200).send(response)
}
})

app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"bindings": [
{
"type": "httpTrigger",
Expand All @@ -18,6 +18,6 @@
"retry": {
"strategy": "fixedDelay",
"maxRetryCount": 4,
"delayInterval": "00:00:01"
"delayInterval": "00:00:03"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
var errorString = 'An error occurred';
var maxRetries = 4;

module.exports = async function (context, timer) {
module.exports = async function (context, req) {
var retryContext = context.executionContext.retryContext;

if (retryContext.maxRetryCount != maxRetries || (retryContext.retryCount > 0 && !retryContext.exception.message.includes(errorString))) {
console.log('Unexpected error');
throw 'Unexpected error';
context.res = {
status: 500
};
} else {
context.log('JavaScript HTTP trigger function processed a request. retryCount: ' + retryContext.retryCount);

if (retryContext.retryCount < maxRetries) {
console.log(errorString);
throw errorString;
throw new Error(errorString);
}
console.log('Execution completed');
context.res = {
body: 'retryCount: ' + retryContext.retryCount
};
}
}
18 changes: 18 additions & 0 deletions sample/NodeRetry/HttpTrigger-RetryHostJson/function.json
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"
}
]
}
22 changes: 22 additions & 0 deletions sample/NodeRetry/HttpTrigger-RetryHostJson/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var errorString = 'An error occurred';
var maxRetries = 2;

module.exports = async function (context, req) {
var retryContext = context.executionContext.retryContext;

if (retryContext.maxRetryCount != maxRetries || (retryContext.retryCount > 0 && !retryContext.exception.message.includes(errorString))) {
debugger;
context.res = {
status: 500
};
} else {
context.log('JavaScript HTTP trigger function processed a request. retryCount: ' + retryContext.retryCount);

if (retryContext.retryCount < maxRetries) {
throw new Error(errorString);
}
context.res = {
body: 'retryCount: ' + retryContext.retryCount
};
}
}
12 changes: 0 additions & 12 deletions sample/NodeRetry/HttpTrigger-RetryWarning/index.js

This file was deleted.

16 changes: 0 additions & 16 deletions sample/NodeRetry/Timer-RetryFunctionJson/function.json

This file was deleted.

7 changes: 6 additions & 1 deletion sample/NodeRetry/host.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"version": "2.0"
"version": "2.0",
"retry": {
"strategy": "fixedDelay",
"maxRetryCount": 2,
"delayInterval": "00:00:03"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class HostJsonFileConfigurationProvider : ConfigurationProvider
{
private static readonly string[] WellKnownHostJsonProperties = new[]
{
"version", "functionTimeout", "functions", "http", "watchDirectories", "watchFiles", "queues", "serviceBus",
"version", "functionTimeout", "retry", "functions", "http", "watchDirectories", "watchFiles", "queues", "serviceBus",
"eventHub", "singleton", "logging", "aggregator", "healthMonitor", "extensionBundle", "managedDependencies",
"customHandler", "httpWorker", "extensions", "concurrency"
};
Expand Down
5 changes: 5 additions & 0 deletions src/WebJobs.Script/Config/ScriptJobHostOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public string RootScriptPath
/// </summary>
public bool IsSelfHost { get; set; }

/// <summary>
/// Gets or sets retry options to use on function executions on function invocation failures.
/// </summary>
public RetryOptions Retry { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the filesystem is read-only.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/WebJobs.Script/Config/ScriptJobHostOptionsSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void Configure(ScriptJobHostOptions options)
{
options.FileLoggingMode = fileLoggingMode.Value;
}
Utility.ValidateRetryOptions(options.Retry);
}

// FunctionTimeout
Expand Down
10 changes: 10 additions & 0 deletions src/WebJobs.Script/Host/ScriptHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@ internal static Collection<CustomAttributeBuilder> CreateTypeAttributes(ScriptJo
var timeoutBuilder = CustomAttributeBuilderUtility.GetTimeoutCustomAttributeBuilder(scriptConfig.FunctionTimeout.Value);
customAttributes.Add(timeoutBuilder);
}
// apply retry settings for function execution
if (scriptConfig.Retry != null)
{
// apply the retry settings from host.json
var retryCustomAttributeBuilder = CustomAttributeBuilderUtility.GetRetryCustomAttributeBuilder(scriptConfig.Retry);
if (retryCustomAttributeBuilder != null)
{
customAttributes.Add(retryCustomAttributeBuilder);
}
}

return customAttributes;
}
Expand Down
2 changes: 1 addition & 1 deletion src/WebJobs.Script/WebJobs.Script.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<PackageReference Include="Microsoft.Azure.Functions.NodeJsWorker" Version="3.3.0" />
<PackageReference Include="Microsoft.Azure.Functions.PowerShellWorker.PS7.0" Version="4.0.1842" />
<PackageReference Include="Microsoft.Azure.Functions.PowerShellWorker.PS7.2" Version="4.0.1847" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="5.0.0-beta.2-10871" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="5.0.0-beta.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.1.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Timers.Storage" Version="1.0.0-beta.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Script.Abstractions" Version="1.0.3-preview" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
Expand All @@ -30,7 +29,7 @@ public SamplesEndToEndTests_CustomHandlerRetry(TestFixture fixture)
}

[Fact]
public async Task HttpTrigger_Retry_LogWarning()
public async Task HttpTrigger_CustomHandlerRetry_Get_Succeeds()
{
await InvokeHttpTrigger("HttpTrigger");
}
Expand All @@ -41,23 +40,8 @@ private async Task InvokeHttpTrigger(string functionName)
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, uri);
var response = await _fixture.Host.HttpClient.SendAsync(request);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
await TestHelpers.Await(() =>
{
var scriptLogs = _fixture.Host.GetScriptHostLogMessages();
return scriptLogs.Where(x => !string.IsNullOrEmpty(x.FormattedMessage) && x.FormattedMessage.Contains("Retries are not supported for function 'Functions.HttpTrigger'.")).Count() == 1;
}, 10000, 1000);
}

[Fact]
public async Task Timer_RetryFunctionJson_WorksAsExpected()
{
await TestHelpers.Await(() =>
{
var scriptLogs = _fixture.Host.GetScriptHostLogMessages();
int attemptsCount = scriptLogs.Where(x => !string.IsNullOrEmpty(x.FormattedMessage) && x.FormattedMessage.Contains("Waiting for `00:00:01` before retrying function execution. Next attempt:")).Count();
bool isSuccessful = scriptLogs.Where(x => !string.IsNullOrEmpty(x.FormattedMessage) && x.FormattedMessage.Contains("Executed 'Functions.TimerTrigger' (Succeeded")).Count() == 1;
return attemptsCount == 4 && isSuccessful;
}, 10000, 1000);
string responseContent = await response.Content.ReadAsStringAsync();
Assert.Equal(responseContent, "Retry Count:2 Max Retry Count:2");
}

public class TestFixture : EndToEndTestFixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Script.Config;
Expand All @@ -27,27 +26,23 @@ public SamplesEndToEndTests_Node_Retry(TestFixture fixture)
}

[Fact]
public async Task Timer_RetryFunctionJson_WorksAsExpected()
public async Task HttpTrigger_RetryFunctionJson_Get_Succeeds()
{
await TestHelpers.Await(() =>
{
var scriptLogs = _fixture.Host.GetScriptHostLogMessages();
int attemptsCount = scriptLogs.Where(x => !string.IsNullOrEmpty(x.FormattedMessage) && x.FormattedMessage.Contains("Waiting for `00:00:01` before retrying function execution. Next attempt:")).Count();
bool isSuccessful = scriptLogs.Where(x => !string.IsNullOrEmpty(x.FormattedMessage) && x.FormattedMessage.Contains("Executed 'Functions.Timer-RetryFunctionJson' (Succeeded")).Count() == 1;
return attemptsCount == 4 && isSuccessful;
}, 10000, 1000);
var response = await SamplesTestHelpers.InvokeHttpTrigger(_fixture, "HttpTrigger-RetryFunctionJson");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string body = await response.Content.ReadAsStringAsync();
Assert.Equal("text/plain", response.Content.Headers.ContentType.MediaType);
Assert.Equal("retryCount: 4", body);
}

[Fact]
public async Task HttpTrigger_Retry_LogWarning()
public async Task HttpTrigger_RetryHostJson_Get_Succeeds()
{
var response = await SamplesTestHelpers.InvokeHttpTrigger(_fixture, "HttpTrigger-RetryWarning");
var response = await SamplesTestHelpers.InvokeHttpTrigger(_fixture, "HttpTrigger-RetryHostJson");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
await TestHelpers.Await(() =>
{
var scriptLogs = _fixture.Host.GetScriptHostLogMessages();
return scriptLogs.Where(x => !string.IsNullOrEmpty(x.FormattedMessage) && x.FormattedMessage.Contains("Retries are not supported for function 'Functions.HttpTrigger-RetryWarning'.")).Count() == 1;
}, 10000, 1000);
string body = await response.Content.ReadAsStringAsync();
Assert.Equal("text/plain", response.Content.Headers.ContentType.MediaType);
Assert.Equal("retryCount: 2", body);
}

public class TestFixture : EndToEndTestFixture
Expand Down
Loading

0 comments on commit e4b2e5e

Please sign in to comment.