Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure function CosmosDbTrigger (Start from the beginning option)

I have a azure function with cosmos db trigger which makes some calculations and write results to db. If something goes wrong i want to have a possibility to start from the first item or specific item make calculations again. Is it possible? Thanks

public static void Run([CosmosDBTrigger(
        databaseName: "db",
        collectionName: "collection",
        ConnectionStringSetting = "DocDbConnStr",
        CreateLeaseCollectionIfNotExists = true,
        LeaseCollectionName = "leases")]IReadOnlyList<Document> input, TraceWriter log)
    {

        ...
    }
like image 289
Metehan Mutlu Avatar asked Sep 01 '25 22:09

Metehan Mutlu


1 Answers

As @Matias Quaranta and @Pankaj Rawat say in the comments, the accept answer is old and is no longer true. You can use StartFromTheBeginning as a C# attribute within your azure function's parameter list like so:

[FunctionName(nameof(MyAzureFunction))]
public async Task RunAsync([CosmosDBTrigger(
    databaseName: "myCosmosDbName",
    collectionName: "myCollectionName",
    ConnectionStringSetting = "cosmosConnectionString",
    LeaseCollectionName = "leases",
    CreateLeaseCollectionIfNotExists = true,
    MaxItemsPerInvocation = 1000,
    StartFromBeginning = true)]IReadOnlyList<Document> documents)
{
    ....
}

Please change the accepted answer.

like image 72
vullnetyy Avatar answered Sep 03 '25 13:09

vullnetyy