The old way of doing things looked as so:
var jobConfig = new JobHostConfiguration(cfg.DocumentDatabase.BlobStorageServer)
{
NameResolver = new Support.BlobNameResolver(_env)
};
jobConfig.Queues.MaxPollingInterval = TimeSpan.FromSeconds(_pollSeconds);
_wjHost = new JobHost(jobConfig);
I am trying to translate this to the new way in 3.0, and this is how far I have come:
_wjHost = new HostBuilder().ConfigureWebJobs(b =>
{
b.AddAzureStorage(x =>
{
x.MaxPollingInterval = TimeSpan.FromSeconds(_pollSeconds);
});
}).ConfigureServices(s =>
{
s.AddSingleton<INameResolver, Support.BlobNameResolver>(_ => new Support.BlobNameResolver(_env));
s.Configure<QueuesOptions>(o =>
{
o.MaxPollingInterval = TimeSpan.FromSeconds(_pollSeconds);
});
}).Build();
Firstly, i don't know which MaxPollingInterval
is the right one to use... so i set both. I assume i shouldn't be using the one in AddBlobStorage
Secondly, and more importantly, where do I specify the blob storage connection string? In the case above, it's the setting stored in cfg.DocumentDatabase.BlobStorageServer
Thanks
So, after staring at the source code for the webjob SDK, I found a kludge. Well, I think it's a kludge. It works and I can now use the new 3.0 SDK.
I am posting this here, mainly because I fear there is no other way to do this using my own configuration files.
If this is wrong, please just let me know and I will delete this answer.
So my code now looks like this:
The line I added was
s.AddSingleton(new StorageAccountProvider(new BlobStorageConfiguration(cfg.DocumentDatabase.BlobStorageServer)));
The webjobs SDK is specifically looking for a key named
Storage
. So I had to implementIConfiguration
and kludge this in as so:and now the trigger is firing just fine. Not pretty. But there is ZERO documentation on the new IHost methods.
In the WebSDK 3, the job is configured via the
appsettings.json
file, the same way it's done for ASP.NET Core.You can see an example on the official Github repo, but I'll also add a more complete example below.
In
appsettings.development.json
, configure it to use the local storage, via theConnectionStrings["AzureWebJobsStorage"]
property:And in
appsettings.json
, configure it for prod:My complete
Program.cs
looks like this (with comments):Just in case someone came to the same situation I had with resolving the queue name when you use QueueTrigger:
You have to use " Microsoft.Extensions.DependencyInjection " package for the below code to work.
Official sample available at WebJob Github
In your Functions, you can pass the connection string key name used in
appsettings.json
ex:
the "AzureWebJobsBlobConnection" is configured in
appsettings.json
as follows:{ "Logging": { ... }, "AzureWebJobsBlobConnection": "...", }
And do not forget to add the configuration in
program.cs
: