question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JobHostConfiguration gone?

See original GitHub issue

I have been using WebJobs in a dotnet core project, so I have code like this:

class Program
{
static void Main(string[] args)
{
var loggerFactory = new LoggerFactory();
using (loggerFactory)
{
IServiceCollection serviceCollection = new ServiceCollection();

            var cfg = ConfigureServices(serviceCollection, loggerFactory);

            var config = new JobHostConfiguration();
            if (config.IsDevelopment)
            {
                config.UseDevelopmentSettings();
            }

            config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(10);
            config.Queues.BatchSize = 1;
            config.JobActivator = new ServiceJobActivator(serviceCollection);
            config.UseTimers();
            config.LoggerFactory = loggerFactory;

            var host = new JobHost(config);

            host.CallAsync(typeof(WebJobsMethods).GetMethod("ProcessMethod"));

            host.RunAndBlock();
        }
    }

This is deployed along with a netcore webapi to an Azure App Service. This code doesn’t compile any more due to JobHostConfiguration being gone… but it probably goes way deeper than that!

Maybe the approach is completely different now? Where do I find the new pattern? Including configuring DI? My webjobs has a continuous job, some timer triggers, and a queuetrigger, configures DI, uses application insights, and logs.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:29 (12 by maintainers)

github_iconTop GitHub Comments

11reactions
KalyanChanumolu-MSFTcommented, Oct 18, 2018

Microsoft.Azure.WebJobs 3.0.1 was released last night & I tried upgrading from 3.0.0-beta5. I see that JobHostConfiguration is missing RunAndBlock() is missing from JobHost QueueTrigger Attribute is missing.

What are the equivalents for these?

4reactions
mathewccommented, Oct 23, 2018

The sample here shows the new host configuration process for a continuous WebJob. That sample doesn’t add/use all possible extensions, it’s meant as a starting point/sample. More notes to answer various questions added above:

  • in general all the previous config.UseXXX extension methods migrated to IHostBuilder builder.AddXXX methods. As in the sample here
  • In order for the builder.AddXXX methods to be present in your solution, you have to add the relevant nuget package for the extension you’re trying to use. E.g.:
    • to use any of the Azure Storage bindings (Queues/Blobs/Tables) you have to add the Microsoft.Azure.WebJobs.Extensions.Storage package and call builder.AddAzureStorage(). You’ll also generally want to call builder.AddAzureStorageCoreServices() to register the storage based implementations of various system services (singleton blob lease management, etc.). This was a big change from v2 - all the Azure Storage bindings used to be baked into the core WebJobs package. We’ve moved them out into their own extension package.
    • to use ServiceBus you have to add the Microsoft.Azure.WebJobs.Extensions.ServiceBus package and call builder.AddServiceBus(). Note that there was an package rename here to standardize our extension package naming. The package used to be called Microsoft.Azure.WebJobs.ServiceBus - don’t use that one in v3.
    • to use Timers you have to add the Microsoft.Azure.WebJobs.Extensions package and call builder.AddTimers(). To use timers, you also need to call builder.AddAzureStorageCoreServices() because timers rely on blob leases behind the scenes
    • and so on for the other extensions. Look for the relevant Microsoft.Azure.WebJobs.Extensions.XXX package, add it to your project and call the builder AddXXX method.
  • to use Application Insights, call builder.AddApplicationInsights() as in the sample here.
  • Yes host.RunAndBlock() is gone - the new pattern is shown in the sample I linked to above (here). I.e. call await host.RunAsync() from your async main method after building the host
Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - New Azure WebJob Project - JobHostConfiguration ...
JobHostConfiguration is now missing. JobHost constructor now has two parameters, including a new IJobHostContextFactory?
Read more >
C# – New Azure WebJob Project – JobHostConfiguration ...
JobHostConfiguration is now missing. JobHost constructor now has two parameters, including a new IJobHostContextFactory? RunAndBlock is missing. It is now ' ...
Read more >
How to use the WebJobs SDK - Azure App Service
The JobHostConfiguration class has a UseDevelopmentSettings method that enables development mode. The following example shows how to use ...
Read more >
Converting Azure WebJobs to .NET Core
This blog post will walk you through steps we did for migration for one our web jobs over to .NET Core. As seen...
Read more >
Solution to "can't be invoked from Azure WebJobs SDK. Is it ...
Is it missing Azure WebJobs SDK attributes? I got this error when I was creating an on-demand WebJob. It should have take a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found