gpt4 book ai didi

Azure Durable Function Orchestration 触发器不触发

转载 作者:行者123 更新时间:2023-12-03 02:44:22 31 4
gpt4 key购买 nike

我正在将 Azure Durable Function 项目从 .NET Core 2.1 升级到 2.2。我将所有 NuGet 包更新到与 .NET Core 2.2 兼容的最新版本(据我所知)。 Durable Client 函数 (StartOrchestration) 配置了一个计时器触发器(如下所示),该触发器按预期工作。

不起作用的是编排触发器函数 (SearchOrchestration) 从未被调用,我不知道为什么。我是否更新到了无效的 NuGet 包?有什么我没有看到的明显错误吗?

作为引用,我一直在查看 Bindings for Durable Functions document看起来我的代码应该可以工作...但事实并非如此。

持久功能编排:

    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");

}

关于Azure Durable Function Orchestration 触发器不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59416437/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com