I'm playing with WebJobs SDK v3.0.5, using a very simple .NET Core 2.2 Console project as follows:
TimerHost.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="3.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Program.cs
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace TimerHost
{
public class Program
{
public static async Task Main()
{
var builder = new HostBuilder();
var host = builder
.UseEnvironment("Development")
.ConfigureServices((context, services) =>
{
services.AddSingleton(context.Configuration);
})
.ConfigureWebJobs(webJobsBuilder =>
{
webJobsBuilder
.AddAzureStorageCoreServices()
.AddTimers();
})
.ConfigureLogging((context, b) =>
{
b.SetMinimumLevel(LogLevel.Debug);
b.AddConsole();
})
.UseConsoleLifetime()
.Build();
await host.RunAsync();
}
}
public static class Function
{
public static void Run([TimerTrigger("*/10 * * * * *")] TimerInfo timer, ILogger logger)
{
logger.LogInformation($"Running job for timer. Next 3 runs are: {timer.FormatNextOccurrences(3)}");
}
}
}
appsettings.json
{
}
The trigger runs fine. However, according to the latest docs (https://learn.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#multiple-instances), the timer should run implicitly as a singleton, which means it should be using an Azure storage account for distributed locking support.
When using Azure Functions locally, I would expect to provide a setting like this:
{
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
}
Otherwise I actually can't run a function, I get an error saying this setting is required, however in the Console host example, I don't get any error at all.
Can someone explain why the console host is not requiring the use of a default storage account? How is the timer maintaining singleton behavior in this scenario?