I'm having a very strange problem with CosmosDB
& Azure Functions
. I frequently delete my database and re-create it in DEV. I then re-deploy the function app. When I call the APIs in the app and CosmosDB triggers are invoked, I normally see the leases
collection created. Here's a typical trigger:
[FunctionName("MyTrigger")]
public static async Task RunAsync([CosmosDBTrigger("MyDatabase", "MyContainer",
ConnectionStringSetting = "CosmosConnectionString", LeaseCollectionName = "leases",
LeaseCollectionPrefix = "MyTrigger", CreateLeaseCollectionIfNotExists = true)]IReadOnlyList<Document> documents,
ExecutionContext executionContext)
{
// code
}
For some reason, the leases
collection is no longer being created. I re-created the database, re-deployed the function app multiple times and made API calls with no luck. What am I missing?
EDIT: I looked at the logs and noticed there are a lot of Microsoft.Azure.Documents.ChangeFeedProcessor.Exceptions.LeaseLostException
exceptions with The lease was lost
message, so I'm not sure what's going on.
EDIT2: Here's a more detailed error message I was able to extract from the logs:
"Either the source collection 'MyContainer' (in database 'MyDatabase') or the lease collection 'leases' (in database 'MyDatabase') does not exist. Both collections must exist before the listener starts. To automatically create the lease collection, set 'CreateLeaseCollectionIfNotExists' to 'true'
Note that CreateLeaseCollectionIfNotExists
is already set to true.