azure - Azure 持久功能编排触发器不触发
问题描述
我正在将 Azure Durable Function 项目从 .NET Core 2.1 升级到 2.2。我将所有 NuGet 包更新为与 .NET Core 2.2 兼容的最新版本(据我所知)。Durable Client 功能 ( StartOrchestration
) 配置有按预期工作的计时器触发器(如下所示)。
不起作用的是编排触发器函数(SearchOrchestration
)从未被调用,我不知道为什么。我是否更新到无效的 NuGet 包?有什么我没有看到的明显错误吗?
作为参考,我一直在查看Bindings for Durable Functions 文档,看起来我的代码应该可以工作……但事实并非如此。
持久的功能编排:
public static class SearchIndexDurableFunctions
{
[FunctionName(nameof(StartOrchestration))]
public static async Task StartOrchestration(
[TimerTrigger("%CronExpression%")]TimerInfo myTimer,
[DurableClient(TaskHub = "%TaskHub:Name%")]IDurableOrchestrationClient starter,
ILogger logger)
{
var nextRunTime = myTimer.Schedule.GetNextOccurrence(DateTime.Now);
logger.LogInformation($">> Next run time will be: {nextRunTime.ToLocalTime()}");
var instanceId = Guid.NewGuid().ToString();
var result = await starter.StartNewAsync(nameof(SearchOrchestration), instanceId);
}
[FunctionName(nameof(SearchOrchestration))]
public static async Task SearchOrchestration(
[OrchestrationTrigger]IDurableOrchestrationContext context,
ILogger logger)
{
try
{
await context.CallActivityAsync(nameof(SearchPartIndexFunctionActivity), null);
await context.CallActivityAsync(nameof(SearchProductIndexFunctionActivity), null);
}
catch (FunctionFailedException ex)
{
logger.LogError(ex, $"Search index orchestration failed.");
}
}
[FunctionName(nameof(SearchPartIndexFunctionActivity))]
public static async Task SearchPartIndexFunctionActivity(
[ActivityTrigger]string input,
ExecutionContext context,
ILogger logger)
{
logger.LogInformation("Started SearchPartIndexFunctionActivity...");
var busLogic = new SearchPartIndexFunctionBase(context, logger);
await busLogic.UpdateIndexAndData();
logger.LogInformation("Finished SearchPartIndexFunctionActivity successfully.");
}
[FunctionName(nameof(SearchProductIndexFunctionActivity))]
public static async Task SearchProductIndexFunctionActivity(
[ActivityTrigger]string input,
ExecutionContext context,
ILogger logger)
{
logger.LogInformation("Started SearchProductIndexFunctionActivity...");
var busLogic = new SearchProductIndexFunctionBase(context, logger);
await busLogic.UpdateIndexAndData();
logger.LogInformation("Finished SearchProductIndexFunctionActivity successfully.");
}
}
显示 NuGet 包版本的 .csproj 文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
<AssemblyName>[Company Name].Interface.Search</AssemblyName>
<RootNamespace>[Company Name].Interface.Search</RootNamespace>
<LangVersion>7.2</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.9.2" />
<PackageReference Include="Microsoft.Azure.Management.Fluent" Version="1.29.0" />
<PackageReference Include="Microsoft.Azure.Management.TrafficManager.Fluent" Version="1.29.0" />
<PackageReference Include="Microsoft.Azure.Search" Version="10.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.0.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Host.Storage" Version="3.0.14" />
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.2.4" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.2" />
<PackageReference Include="[Company Name].Core.Repositories" Version="1.0.20191218.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
解决方案
似乎问题来自你的[DurableClient(TaskHub = "%TaskHub:Name%")]
其他代码没有问题。
功能在我这边工作是这样的:
public static void TimerStart(
[TimerTrigger("*/1 * * * * *")]TimerInfo myTimer,
[DurableClient]IDurableOrchestrationClient starter,
ILogger log)
{
// Function input comes from the request content.
log.LogInformation($"==================================Started orchestration with ID");
}
推荐阅读
- haskell - map sum [[]] 的结果不对?
- javascript - 单击两个或多个按钮时弹出 Javascript
- r - 在 lm() 上使用 anova() 进行交互的综合 anova 忽略了一个因素
- python-3.x - “无法在应该开箱即用的项目上创建 cudnn 句柄:CUDNN_STATUS_ALLOC_FAILED”
- c - C读取文本文件并将内容放入结构中
- python - 为什么我收到 TypeError: cannot unpack non-iterable builtin_function_or_method 对象?
- javascript - 从道具反应传递列表到状态
- javascript - socket.io 将数据发送到匹配的套接字
- reactjs - 在 React Concurrent 中显示加载状态但也显示以前的结果会给出警告
- php - 升级到7.4后Win10上的PHP CLI不再加载本地ini文件