我正在尝试实施 Azure Durable Function 工作流。
每 6 分钟我就有一个 Azure TimerTrigger 函数调用一个 Azure 编排函数 (OrchestrationTrigger),它依次启动许多活动函数 (ActivityTrigger)。
然而,有时,Orchestration 函数会在几秒钟内被调用两次!这是一个大问题,因为我的活动函数不是幂等的!
下面是我的代码是如何被调用的。
定时器触发功能:
[FunctionName("StartupFunc")]
public static async Task Run([TimerTrigger("0 */6 * * * *", RunOnStartup = true, UseMonitor = false)]TimerInfo myStartTimer, [OrchestrationClient] DurableOrchestrationClient orchestrationClient, TraceWriter log)
{
List<OrchestrationModel> ExportModels = await getData();
string id = await orchestrationClient.StartNewAsync("OrchestratorFunc", ExportModels);
}
Run Code Online (Sandbox Code Playgroud)
编排功能:
[FunctionName("OrchestratorFunc")]
public static async Task<string> TransformOrchestration([OrchestrationTrigger] DurableOrchestrationContext context, TraceWriter log)
{
var dataList = context.GetInput<List<OrchestrationModel>>();
var tasks = new List<Task>();
foreach (var data in …Run Code Online (Sandbox Code Playgroud) 我需要有关使用 blob 触发器编写持久函数的帮助,任何人都可以提供帮助。
我已经创建了一个 Blob 触发器函数,它将处理进入 Blob 的任何新文件,现在我需要将 Blob 触发器函数迁移到持久函数,并且我在持久函数中没有看到任何用于 Blob 触发器的选项,任何人都可以指导我?
我有一组 Durable Azure Functions,它们是使用异步模式编写的,如here所述。
在研究了应用洞察中的日志后,我发现我的所有功能都出现了反复出现的故障。
这是对 DurableFunctionsHubInstances 表的 GET 调用。下面的调用会产生 404 响应。
https://mydomain.table.core.windows.net:443/DurableFunctionsHubInstances(PartitionKey= 'f6eb7829ab6f4020af0431ab0115164a',RowKey = '')?$选择=流程id,名称,版本,输出,CustomStatus,CreatedTime,LastUpdatedTime,RuntimeStatus,PartitionKey ,RowKey,时间戳,ETag
这种依赖失败正常吗?我猜这可能是对日志表的初始调用,以检查是否存在需要拾取并继续的预先存在的实例。
但是,我不知道这一事实,并且很想澄清这一点。
azure azure-functions azure-durable-functions azure-function-async
我可以看到 azure 持久函数使用存储帐户来管理状态和检测。当在具有大量数据的环境中运行持久函数时,表和队列会变得越来越大,并且速度会越来越慢。持久功能清理是否会自行记录它们,或者这是您需要自己完成的任务吗?
在 Azure Durable Functions 上实现扇出/扇入模式时,是否有办法控制最大并行度?
我目前正在实现此模式来执行数据加载过程,但我遇到了 DTU 的数据库限制,因为操作数量太多,数据库无法处理。
我正在考虑的解决方案涉及使用以下属性:
( host.json ) 文件与以下内容结合使用:
前 2 个属性应限制每个主机的并行函数执行数量,而 WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT 应限制主机数量。
这是限制最大并行度的正确方法吗?
此代码直接来自 Visual Studio 2019 中的 Durable Function 启动
[FunctionName("Orchestrator_HttpStart")]
public static async Task<HttpResponseMessage> HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
[DurableClient] IDurableOrchestrationClient starter,
ILogger log)
{
// Function input comes from the request content.
string instanceId = await starter.StartNewAsync("Orchestrator", null);
log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
return starter.CreateCheckStatusResponse(req, instanceId);
}
Run Code Online (Sandbox Code Playgroud)
IDurableOrchestationClient starter&的值ILogger log来自哪里?由于这些参数不会在 HTTP 请求中传递,我假设幕后一定有一些 IoC 魔法发生,但我不完全确定它是什么/在哪里。
c# dependency-injection azure azure-functions azure-durable-functions
我已经编写了第一个持久函数,我想知道在协调器函数中使用 foreach 循环是否可能/良好的做法?
编排中的第一个活动返回项目 ID 列表,我想循环遍历该列表并使用子编排为每个项目 ID 执行一系列活动。
我创建了一个测试函数,它似乎有效。我观察到的唯一行为是,每次协调器重播并且当它到达 foreach 循环时,它都会迭代整个列表,直到到达当前项目,然后执行活动。
任何建议/意见将不胜感激。
谢谢
我有一个 OrchestrationTrigger 函数,可以通过 http 请求调用另一个服务。
[FunctionName("MyFunc")]
public async Task RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext context,
ILogger logger)
{
var req = new DurableHttpRequest(HttpMethod.Post, _uri, headers, jsonBody);
var res = await context.CallHttpAsync(req);
// Do something
}
Run Code Online (Sandbox Code Playgroud)
但出现以下错误:
检测到多线程执行。如果 Orchestrator 函数代码等待的任务不是由 DurableOrchestrationContext 方法创建的,则可能会发生这种情况。更多详细信息可以在这篇文章中找到 :https://learn.microsoft.com/en-us/azure/azure-functions/durable-functions-checkpointing-and-replay#orchestrator-code-constraints。
那里的官方文档建议使用 context.CallHttpAsync- 正是我所做的。
我想创建一个 Azure Durable Function,它将从 Internet 下载 CSV,并根据此文件中的数据,使用 EntityFramework 更新我的数据库。
我设置了使用 TimeTrigger 触发的简单启动功能。该函数负责启动协调器。协调器并行执行多个活动。大约有 40000 个工作项需要处理,这就是 Orchestrator 触发的活动数量。其中一些活动需要更新数据库(插入/更新/删除行)。为此,我需要一个数据库连接。我可以通过以下方式在 StartUp 中配置 DI:
public override void Configure(IFunctionsHostBuilder builder)
{
var connectionString = Environment.GetEnvironmentVariable("DefaultConnection");
builder.Services.AddDbContext<SqlContext>(options => options.UseSqlServer(connectionString));
builder.Services.AddScoped<IDbContext, SqlContext>();
}
}
Run Code Online (Sandbox Code Playgroud)
然而,我的所有函数(协调器、活动函数等)都是静态的,并且驻留在静态类中。我还没有看到任何在非静态类中定义持久函数的例子,当我自己尝试时,我遇到了各种各样的问题,所以我假设它们必须是静态的,而无需深入研究它。
我不知道如何将我的DbContext对象传递给 Activity 函数,以便它可以在需要时更新数据库中的数据。
我该如何解决呢?
dependency-injection azure .net-core azure-functions azure-durable-functions
我必须对项目列表运行一个函数。我正在使用 Azure Durable Functions,并且可以使用其扇出/扇入策略并行运行这些项目。
Parallel.ForEachAsync但是,我想知道这样做与在单个 Activity 函数中使用新方法之间存在什么区别。我需要使用持久函数,因为这是一个永恒的编排,在完成后会重新启动。
c# performance azure azure-functions azure-durable-functions