Azure 持久功能编排触发器不触发
Azure Durable Function Orchestration Trigger Doesn't Fire
我正在将 Azure Durable Function 项目从 .NET Core 2.1 升级到 2.2。我将所有 NuGet 包更新为与 .NET Core 2.2 兼容的最新版本(据我所知)。持久客户端功能 (StartOrchestration
) 配置了定时器触发器(如下所示),它按预期工作。
没有工作的是 Orchestration Trigger 函数 (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");
}
出于历史目的
我在生产环境中进行了部署,一切都运行良好。当我创建一个 DEV 插槽时,问题就来了。
有时生产函数"said"表示任务执行成功。然而,什么也没做。然后该功能将重新启动,一切都会再次运行。
但问题总是回来,对我来说,在调用 StartNew
时,编排器不是 运行
最后我发现,由于 DEV 和 PROD 环境共享相同的 Table 存储,DEV 环境在处理生产请求时
很忙。为了解决这个问题,我必须为每个插槽
部署具有不同集线器名称的 host.json
我正在将 Azure Durable Function 项目从 .NET Core 2.1 升级到 2.2。我将所有 NuGet 包更新为与 .NET Core 2.2 兼容的最新版本(据我所知)。持久客户端功能 (StartOrchestration
) 配置了定时器触发器(如下所示),它按预期工作。
没有工作的是 Orchestration Trigger 函数 (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");
}
出于历史目的
我在生产环境中进行了部署,一切都运行良好。当我创建一个 DEV 插槽时,问题就来了。
有时生产函数"said"表示任务执行成功。然而,什么也没做。然后该功能将重新启动,一切都会再次运行。 但问题总是回来,对我来说,在调用 StartNew
时,编排器不是 运行最后我发现,由于 DEV 和 PROD 环境共享相同的 Table 存储,DEV 环境在处理生产请求时 很忙。为了解决这个问题,我必须为每个插槽
部署具有不同集线器名称的 host.json