持久函数 - 无限执行状态不起作用
Durable Functions - infinite execution with state doesn't work
我正在设置一个持久函数,它应该 运行 通过每小时调用自身并保持状态来无限地使用。函数编译,总线在 运行 失败并出现以下错误:
2017-07-12T07:04:05.614 Exception while executing function: Functions.DurableTimer.
Microsoft.Azure.WebJobs.Host: Exception binding parameter 'context'.
Microsoft.Azure.WebJobs.Extensions.DurableTask: Cannot convert to DurableOrchestrationContext.
功能代码
#r "Microsoft.Azure.WebJobs.Extensions.DurableTask"
using System;
using System.Threading;
public static async Task Run(DurableOrchestrationContext context, TraceWriter log)
{
log.Info($"Durable function executed at: {context.CurrentUtcDateTime}");
// sleep for one hour between calls
DateTime nextExecution = context.CurrentUtcDateTime.AddHours(1);
await context.CreateTimer(nextExecution, CancellationToken.None);
int counterState = context.GetInput<int>();
log.Info($"Counter state: {counterState}");
counterState++;
context.ContinueAsNew(counterState);
}
function.json
{
"bindings": [
{
"name": "context",
"type": "orchestrationTrigger",
"direction": "in"
}
],
"disabled": false
}
我的猜测是您试图在门户 UI 中手动触发编排功能,很遗憾,目前不支持该功能。我通过尝试重现您的确切场景并单击门户中的 运行 按钮进行了验证。我已经打开一个错误来跟踪这个问题:https://github.com/Azure/azure-functions-durable-extension/issues/10
假设是这种情况,您可以通过创建一个单独的函数来解决它,该函数知道如何触发您的协调器函数。这是我在 GitHub 问题中发布的示例:
代码
#r "Microsoft.Azure.WebJobs.Extensions.DurableTask"
using System;
public static async Task Run(string functionName, DurableOrchestrationClient starter, TraceWriter log)
{
log.Info($"Starting orchestration named: {functionName}");
string instanceId = await starter.StartNewAsync(functionName, null);
log.Info($"Started orchestration with ID = '{instanceId}'.");
}
function.json
{
"bindings": [
{
"type": "manualTrigger",
"direction": "in",
"name": "functionName"
},
{
"name": "starter",
"type": "orchestrationClient",
"direction": "in"
}
],
"disabled": false
}
这是一个通用函数,可以按名称启动任何协调器函数。在您的情况下,您可以将 DurableTimer
作为输入。
抱歉,这不是显而易见的,感谢您在我们顺利解决此问题时的耐心等待。 :)
我正在设置一个持久函数,它应该 运行 通过每小时调用自身并保持状态来无限地使用。函数编译,总线在 运行 失败并出现以下错误:
2017-07-12T07:04:05.614 Exception while executing function: Functions.DurableTimer. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'context'. Microsoft.Azure.WebJobs.Extensions.DurableTask: Cannot convert to DurableOrchestrationContext.
功能代码
#r "Microsoft.Azure.WebJobs.Extensions.DurableTask"
using System;
using System.Threading;
public static async Task Run(DurableOrchestrationContext context, TraceWriter log)
{
log.Info($"Durable function executed at: {context.CurrentUtcDateTime}");
// sleep for one hour between calls
DateTime nextExecution = context.CurrentUtcDateTime.AddHours(1);
await context.CreateTimer(nextExecution, CancellationToken.None);
int counterState = context.GetInput<int>();
log.Info($"Counter state: {counterState}");
counterState++;
context.ContinueAsNew(counterState);
}
function.json
{
"bindings": [
{
"name": "context",
"type": "orchestrationTrigger",
"direction": "in"
}
],
"disabled": false
}
我的猜测是您试图在门户 UI 中手动触发编排功能,很遗憾,目前不支持该功能。我通过尝试重现您的确切场景并单击门户中的 运行 按钮进行了验证。我已经打开一个错误来跟踪这个问题:https://github.com/Azure/azure-functions-durable-extension/issues/10
假设是这种情况,您可以通过创建一个单独的函数来解决它,该函数知道如何触发您的协调器函数。这是我在 GitHub 问题中发布的示例:
代码
#r "Microsoft.Azure.WebJobs.Extensions.DurableTask"
using System;
public static async Task Run(string functionName, DurableOrchestrationClient starter, TraceWriter log)
{
log.Info($"Starting orchestration named: {functionName}");
string instanceId = await starter.StartNewAsync(functionName, null);
log.Info($"Started orchestration with ID = '{instanceId}'.");
}
function.json
{
"bindings": [
{
"type": "manualTrigger",
"direction": "in",
"name": "functionName"
},
{
"name": "starter",
"type": "orchestrationClient",
"direction": "in"
}
],
"disabled": false
}
这是一个通用函数,可以按名称启动任何协调器函数。在您的情况下,您可以将 DurableTimer
作为输入。
抱歉,这不是显而易见的,感谢您在我们顺利解决此问题时的耐心等待。 :)