I need to use StartFromTime as we have a requirement to upload a historical data seed from the cosmos db to the target db that will run and then the change feed processor will pick up after that process is done.
Once I implemented StartFromTime, my deployed code started failing with this error.
"The listener for function 'x' was unable to start. The listener is already starting."
Adding this property was my only change.
Running this locally works just fine.
I deleted my lease records and they are not recreating themselves.
Here is my change feed function.
[FunctionName("XChangeFeedProcessor")]
public async Task Run([CosmosDBTrigger(
databaseName: "%cosmosDbName%",
containerName: "X",
Connection = "ConnectionStrings:CosmosDB",
LeaseContainerName = "XLeaseCollection",
LeaseContainerPrefix = "%leaseContainerPrefix%",
CreateLeaseContainerIfNotExists = true,
StartFromTime = "%startFromTime%")]IReadOnlyCollection<JObject> documents)
Here's my callstack
Microsoft.Azure.WebJobs.Host.Listeners.FunctionListenerException:
System.InvalidOperationException:
at Microsoft.Azure.WebJobs.Extensions.CosmosDB.CosmosDBTriggerListener`1+<StartAsync>d__26.MoveNext (Microsoft.Azure.WebJobs.Extensions.CosmosDB, Version=4.4.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: D:\a\_work\1\s\src\WebJobs.Extensions.CosmosDB\Trigger\CosmosDBTriggerListener.cs:91)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Listeners.FunctionListener+<StartAsync>d__13.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.39.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Listeners\FunctionListener.cs:68)
I updated all my nuget packages to the latest and deployed and that did not help.
I redeployed without the StartFromTime and the function worked as expected.
https://github.com/Azure/azure-webjobs-sdk-extensions/issues/817 did not help me
So it turns out that Microsoft tech support can see more logs in app insights than I can. Why is this?!
The bicep file I used to deploy to the function's configuration for the StartFromTime had a date format of 2020-01-01T00:00:00Z but after it got deployed, the format was converted to 2020/01/01 00:00:00 and the function could not parse this. Once tech support showed me the error, I manually updated the date and it worked properly. I am filling a bug report with Microsoft about this.