我正在将Azure耐用功能项目从.NET Core 2.1升级到2.2。我已将所有NuGet软件包更新为与.NET Core 2.2兼容的最新版本(据我所知)。耐用客户端功能(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>
答案 0 :(得分:1)
问题似乎来自您的[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");
}
答案 1 :(得分:0)
出于历史目的
我部署到生产环境中,一切运行正常。当我创建DEV插槽时出现了问题。
有时生产功能“说”该任务已成功执行。但是,什么也没做。然后,该功能将重新启动,一切将再次正常运行。 但是问题总是返回,对我来说,协调器在调用StartNew时没有运行
最后,我发现,由于DEV和PROD环境共享同一个表存储,因此DEV环境在处理生产请求时 很忙为了解决这个问题,我必须为每个插槽部署具有不同集线器名称的host.json