Я собрал небольшой небольшой пример кода сохранения ваших функций. Я использовал триггер HTTP, поскольку он облегчил тестирование, но логика хранения таблиц была бы такой же в вашем триггере Activity.
public class FunctionExecution : TableEntity
{
public string FunctionName { get; set; }
}
public static class HttpTriggeredFunction
{
[FunctionName("HttpTriggeredFunction")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
[Table("FunctionExecutions", Connection = "StorageConnectionString")] CloudTable table,
ExecutionContext executionContext,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
// query table storage for all entries (you might want to restrict the query to the last day etc)
TableQuery<FunctionExecution> query = new TableQuery<FunctionExecution>();
TableQuerySegment<FunctionExecution> data = await table.ExecuteQuerySegmentedAsync(query, null);
// get the last function execution by ordering by Timestamp
FunctionExecution lastFunctionExecution = data.OrderByDescending(r => r.Timestamp).FirstOrDefault();
DateTimeOffset? begin = lastFunctionExecution?.Timestamp;
DateTime end = DateTime.UtcNow;
// call off to ThirdPartyClient
// log successful execution to table storage
TableOperation insertOperation = TableOperation.Insert(new FunctionExecution
{
PartitionKey = executionContext.InvocationId.ToString(), // using the InvocationId of the function so you can relate executions if needed
RowKey = Guid.NewGuid().ToString(),
Timestamp = DateTimeOffset.UtcNow, // set the Timestamp to now as the function has been successful
FunctionName = "HttpTriggeredFunction" // optional but you might want to save the function name in your case FunctionNames.GetInvoicesAsync
});
await table.ExecuteAsync(insertOperation);
return new OkObjectResult(null);
}
}
Редактировать : Подумал - возможно, вы захотите установить имя функции в качестве ключа разделения, чтобы обеспечить лучшее разбиение (при необходимости):
TableOperation insertOperation = TableOperation.Insert(new FunctionExecution
{
PartitionKey = "HttpTriggeredFunction", // a partition is a consecutive range of entities possessing the same partition key value
RowKey = Guid.NewGuid().ToString(), // row key must be unique within a partition
Timestamp = DateTimeOffset.UtcNow, // set the Timestamp to now as the function has been successful
InvocationId = executionContext.InvocationId.ToString() // optional - using the InvocationId of the function so you can relate executions if needed
});
Надеюсь, это поможет!