question

2JK avatar image
0 Votes"
2JK asked AnuragSingh-MSFT answered

Azure Function not storing checkpoint and processing the same documents

Hi.

I have an Azure Function that is triggered by a CosmosDB document insertion/update. When I run the function, it always captures the same item/document and runs from there. The continuation token in the leases container does not update. I thought if the function processes a certain document, it stores a checkpoint of that and knows where to continue from. Why is my function not doing that?

I have two function.json files (two functions), with each listening to a container but basically go through the same logic. I only have an input binding which is the CosmosDB trigger, and each has a different lease container. No output binding as I use the Cosmos client to upsert items into new containers I created in the same DB. I'm running my code locally in VSCode with python.

The function.json (the other is the same but with a different collectionName and leasesCollectionName):

 {
   "scriptFile": "__init__.py",
   "bindings": [
     {
       "type": "cosmosDBTrigger",
       "name": "docs",
       "direction": "in",
       "leaseCollectionName": "leases",
       "connectionStringSetting": "cosmostest_DOCUMENTDB",
       "databaseName": "db-test",
       "collectionName": "collection-one",
       "createLeaseCollectionIfNotExists": true
     }
 }

Any help would be appreciated.

azure-functionsazure-cosmos-db
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AnuragSingh-MSFT avatar image
0 Votes"
AnuragSingh-MSFT answered

Hi @2JK,

Welcome to Microsoft Q&A! Apologies for the delay in getting back to this.

The lease container maintains state across multiple and dynamic serverless Azure Function instances and enables dynamic scaling. Azure Functions (with "trigger type": "cosmosDBTrigger") gets automatically triggered on each new event in your Azure Cosmos container's change feed.

Based on the symptom of issue reported, please refer to the document for "Common scenarios and workaround in Azure Cosmos DB Triggers". This contains common troubleshooting scenarios and corresponding measures to rectify them.
Please let me know if you have any questions.


Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.