Azure Durable Function 不会创建存储 table 实体

Azure Durable Function doesn't create a storage table entity

我有一个持久函数,我想在它们进入存储队列后立即使用它来聚合计算结果。此外,我希望该函数在名为“result”的 Azure 存储 table 上创建一个 table 实体。

函数按预期工作,但没有创建单个 table 实体。但是,当我通过 https://func-foobar.azurewebsites.net/api/create 调用我的测试触发器 TestTrigger 时?创建了 table 个条目。

这是为什么?我在这里做错了什么?

namespace Aggregator
{
    public static class AggregatorFunction
    {
        public class ResultEntity
        {
            public string PartitionKey { get; set; }

            public string RowKey { get; set; }

            public uint Run { get; set; }

            public decimal IntermediatePi { get; set; }
        }

        [FunctionName("Counter")]
        [return: Table("result")]
        public static ResultEntity Counter
        (
            [EntityTrigger] IDurableEntityContext ctx,
            ILogger log
        )
        {
            switch (ctx.OperationName.ToLowerInvariant())
            {
                case "add":
                    var unit = ctx.GetInput<UnitOfWork>();
                    log.LogInformation($"Processing: {unit}");

                    (decimal IntermediatePi, ulong IntermediateHits, uint run) = ctx.GetState<(decimal, ulong, uint)>();

                    IntermediateHits += unit.NumHits;
                    IntermediatePi = (decimal)IntermediateHits / unit.TotalRuns * 4.0m;
                    run += 1;

                    log.LogInformation($"==> State: run={run} intermediateHits={IntermediateHits} intermediatePi={IntermediatePi}");
                    ctx.SetState((IntermediatePi, IntermediateHits, run));

                    return new ResultEntity
                    {
                        PartitionKey = "Pi",
                        RowKey = Guid.NewGuid().ToString(),
                        Run = run,
                        IntermediatePi = IntermediatePi
                    };

                case "delete":
                    log.LogInformation("Deleting state!");
                    ctx.DeleteState();

                    return null;
            }

            return null;
        }

        [FunctionName("QueueTrigger")]
        public static async Task Run
        (
            [QueueTrigger(queueName: "results")] string json,
            [DurableClient] IDurableEntityClient entityClient
        )
        {
            var unit = JsonSerializer.Deserialize<UnitOfWork>(json);
            var entityId = new EntityId("Counter", "CounterKey");
            await entityClient.SignalEntityAsync(entityId, "add", unit);
        }

        [FunctionName("HttpResetTrigger")]
        public static async Task Reset
        (
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "reset")] HttpRequest req,
            [DurableClient] IDurableEntityClient entityClient
        )
        {
            var entityId = new EntityId("Counter", "CounterKey");
            await entityClient.SignalEntityAsync(entityId, "delete", null);
        }

        [FunctionName("TestTrigger")]
        [return: Table("result")]
        public static ResultEntity CreateTable
        (
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "create")] HttpRequest req
        )
        {
            return new ResultEntity
            {
                PartitionKey = "Test",
                RowKey = Guid.NewGuid().ToString(),
                Run = 1,
                IntermediatePi = ulong.MaxValue
            };
        }
    }
}   

还没有尝试过类似的东西,但文档是这样说的 (https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-bindings?tabs=csharp#trigger-behavior):

Warning

Orchestrator functions should never use any input or output bindings other than the orchestration trigger binding. Doing so has the potential to cause problems with the Durable Task extension because those bindings may not obey the single-threading and I/O rules. If you'd like to use other bindings, add them to an activity function called from your orchestrator function. For more information about coding constraints for orchestrator functions, see the Orchestrator function code constraints documentation.

所以这里正确的方法是对 table 实体写入使用 activity 函数。