MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.13k stars 21.21k forks source link

There is no documentation how to use `TimerTrigger` with isolated (out-of-process) function. #84986

Open damianfijorek opened 2 years ago

damianfijorek commented 2 years ago

Wron package is mentioned. Should be Microsoft.Azure.Functions.Worker.Extensions.Timer. See AZFW0001: Invalid binding attributes.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

PramodValavala-MSFT commented 2 years ago

@damianfijorek Thanks for the feedback! The package that you mention is only for the C# Isolated Worker while the rest of the languages including in-process C# use the packages listed here. Either way, I believe it would be best to include this information in the reference docs as well. I am assigning this issue to the content author for further review.

damianfijorek commented 2 years ago

Thank you. You make me aware that there are differences between in-process and isolated functions. This makes it clearer. One big difference is that it's hard to make isolated work and most of the documentation or SO answers won't help you. When you use cutting edge technology be prepared to get cut. 😉 Fortunately, with .NET 6 you can choose to use in-process.

I could not find documentation of triggers specific to isolated process. There is more to make it work with isolated:

Then I've got this error when running locally The listener for function 'TimerTriggerCSharp' was unable to start. Microsoft.Azure.WebJobs.Extensions.Timers.Storage: Could not create BlobContainerClient for ScheduleMonitor. I've used the QueueTrigger before where it's well documented and quite obvious that you need to configure connection to Azure Queue. For TimerTrigger you need connection to Azure Storage and the way to provide is AzureWebJobsStorage app setting. This is already configured in Azure with the required storage account for Function App. It's added locally when you create project but it does not work with QueuTrigger (Microsoft.Azure.WebJobs.Extensions.Storage: Storage account connection string 'AzureWebJobsAzureStorage' does not exist. Make sure that it is a defined App Setting.). 🤷🏻‍♂️ So I just changed the setting name. To have both working you need the AzureWebJobsAzureStorage (just AzureStorage works too 🤷🏻‍♂️) and AzureWebJobsAzureStorage configured.

[Function("TimerTriggerCSharpIsolated")]
public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, FunctionContext functionContext)
{
    var log = functionContext.GetLogger<TimerTriggerCSharpIsolated>()
    if (myTimer.IsPastDue)
    {
        log.LogInformation("Timer is running late!");
    }
    log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
ggailey777 commented 2 years ago

@damianfijorek sorry we are still catching up with the isolated process documentation in the binding references. In the meantime, the reference samples are available here: https://github.com/Azure/azure-functions-dotnet-worker/tree/main/samples/Extensions Specifically, the Timer trigger sample is here: https://github.com/Azure/azure-functions-dotnet-worker/blob/main/samples/Extensions/Timer/TimerFunction.cs

Bouke commented 9 months ago

Where/how is TimerInfo defined?

underscoreHao commented 9 months ago

Where/how is TimerInfo defined?

I was also a bit puzzled around this since I was migrating an old function to the new v4 isolated process and the template spewed some custom class for me in the trigger.

It seems TimerInfo is in the Microsoft.Azure.Functions.Worker.Extensions.Timer package (for isolated process)

<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.2.0" />