Home > Software design >  Azure Function for Cosmos DB change feed feed won't run: No job functions found
Azure Function for Cosmos DB change feed feed won't run: No job functions found

Time:09-24

I'm writing an Azure Function app that'll subscribe to a Cosmos DB change feed. When I use Visual Studio 2019 to run the app locally (F5), I get the following error on the CLI:

Azure Function Core Tools reports "No job functions found."

The entire code snippet is below:

using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;

namespace ZZZ.ChangeFeedSubscriber
{
    public static class ChangeFeedSubscriber
    {
        [FunctionName("ChangeFeedSubscriber")]
        public static void Run([CosmosDBTrigger(
            databaseName: "XXX",
            collectionName: "YYY",
            ConnectionStringSetting = "XXX",
            LeaseCollectionName = "leases")] IReadOnlyList<Doc> docs, FunctionContext context)
        {
            var logger = context.GetLogger("ChangeFeedSubscriber");

            if (docs != null && docs.Count > 0)
            {
                logger.LogInformation("Documents modified: "   docs.Count);

                foreach (var doc in docs)
                {
                    logger.LogInformation("ID: "   doc.id);
                }
            }
        }
    }
}

I tried to set "--verbose" on the application arguments to see log output but it threw an error.

Adding "--verbose" throws an error.

Result of adding "--verbose" to application arguments.

I also tried setting "start --verbose" but it threw an error, too.

Adding "start --verbose" also throws an error.

Result of adding "start --verbose" to application arguments.

I don't know what else I can check at this point. The application won't start up and I cannot see log output based on the searching I've done.

Any help would be appreciated. TIA!

CodePudding user response:

Looks like you have mixed the in-proc and out-of-process model here, which caused the issue.

From the code, I am assuming you have an out of process (isolated worker) function app. But your second line is a using statement to import the Microsoft.Azure.WebJobs namespace. I also see you are using the FunctionName attribute which is coming from the Microsoft.Azure.WebJobs package.

For out of process function apps, you should not use the webjobs package. Instead, you should use the equivalent pacakge from Microsoft.Azure.Functions.Worker.Extensions

To fix, open your .csproj file and remove the Microsoft.Azure.WebJobs.Extensions.CosmosDB package. Add a new entry for Microsoft.Azure.Functions.Worker.Extensions.CosmosDB (the out of process worker version). You may do the same using nuget package manager UI as well.

After the change, your csproj file will look something like this

<ItemGroup>
  <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.CosmosDB" Version="3.0.9" />
  <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.0.3" OutputItemType="Analyzer" />
  <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.1.0" />
</ItemGroup>

Also make sure that now you are using the Function attribute instead of FunctionName and removed the using statement to import Microsoft.Azure.WebJobs namespace.

[Function("Function1")]                
public static void Run([CosmosDBTrigger(

With this change, your functions will be discovered.

  • Related