我有一个由 CosmosDb 插入/更新触发的函数,我将每个文档复制到一个存储 blob。调试时,该函数会一遍又一遍地为相同的少数文档触发。
我尝试限制处理的文档数量,但这使得它只能一遍又一遍地处理相同的 N 个文档。我尝试在触发器集合(和租约集合)上提高 RU,但没有效果。
[FunctionName("Function1")]
public async static Task Run([CosmosDBTrigger(
databaseName: "Events",
collectionName: "DomainEvents",
ConnectionStringSetting = "cosmosConnectionString",
CreateLeaseCollectionIfNotExists = true,
LeaseCollectionName = "DomainEventLeases")]IReadOnlyList<Document> input, ILogger log, ExecutionContext context)
{
if (input != null && input.Count > 0)
{
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
CloudStorageAccount cloudStorageAccount;
if (CloudStorageAccount.TryParse(config["StorageConnectionAppSetting"], out cloudStorageAccount))
{
var client = cloudStorageAccount.CreateCloudBlobClient();
var container = client.GetContainerReference("wormauditlog");
foreach(var thisDocument in input)
{
var blob = container.GetBlockBlobReference(thisDocument.Id);
try
{
await blob.UploadFromByteArrayAsync(thisDocument.ToByteArray(), 0, thisDocument.ToByteArray().Length);
}
catch(Exception e)
{
throw;
}
}
}
else
{
throw new FunctionInvocationException("Bad storage connection string.");
}
}
}