I am writing some code that implements event sourcing using Cosmos as my storage. My initial documents are written successfully to the collection. I have then set up an Azure function that triggers on changes to that collection's feed and copies the item to another collection.
My problem is that while this all works fine if I am debugging the functions app locally (the changes come through and are processed without issue) the function is not triggered once published as a functions app. The function exists but the total execution count is always 0. It's like the function isn't running on the timer and checking the feed. Other functions in my functions app work as expected.
My function code is
[FunctionName("EventSourceWrite")]
public static void Run([CosmosDBTrigger(
databaseName: "Puffin",
collectionName: "EventSource",
ConnectionStringSetting = "EventSourceConnection",
CreateLeaseCollectionIfNotExists = true,
LeaseCollectionName = "leases")]IReadOnlyList<Document> input, ILogger log)
{
if (input != null && input.Count > 0)
{
log.LogInformation("Documents modified " + input.Count);
log.LogInformation("First document Id " + input[0].Id);
var container = Cosmos.GetItemsContainer();
foreach (var doc in input)
{
var item = JsonConvert.DeserializeObject<Item>(doc.ToString());
// reset the Id
item.Id = item.ItemId;
if(!string.IsNullOrEmpty(item.CollectionId))
{
container.UpsertItemAsync(item, new Microsoft.Azure.Cosmos.PartitionKey(item.CollectionId));
}
}
}
}
Please check that do you have EventSourceConnection in your application settings of your function app. If no, please add new one and try again.