Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure WebJobs SDK - in what scenarios is creation of a JobHost object required?

Most of the samples associated with the Azure WebJobs SDK have startup code that looks like this:

static void Main()
{
    JobHost h = new JobHost();
    h.RunAndBlock();
}

However you can also kick off a WebJob without creating a JobHost object like this:

static void Main()
{
    // Do something...
}

In what scenarios is the JobHost necessary?

like image 778
Emilio Avatar asked Sep 12 '14 15:09

Emilio


People also ask

What is JobHost in Azure?

The JobHost is the entry point for the Azure WebJobs SDK. It is responsible for indexing, publishing, monitoring and scheduling the functions defined using WebJobs SDK artifacts. Whenever you want to invoke a WebJobs SDK function (triggered or manual/called) you need an instance of the JobHost .

What is the use of WebJobs in Azure?

WebJobs is a feature of Azure App Service that enables you to run a program or script in the same instance as a web app, API app, or mobile app. There is no additional cost to use WebJobs. You can use the Azure WebJobs SDK with WebJobs to simplify many programming tasks.

What is Azure WebJobs SDK?

The Azure WebJobs SDK is a framework that simplifies the task of writing background processing code that runs in Azure WebJobs. It includes a declarative binding and trigger system that works with Azure Storage Blobs, Queues and Tables as well as Service Bus.

Which Azure websites feature should you enable for continuously running WebJobs?

If you set the web app that hosts your job to run continuously, run on a schedule, or use event-driven triggers, enable the Always on setting on your web app's Azure Configuration page. The Always on setting helps to make sure that these kinds of WebJobs run reliably.


2 Answers

WebJobs and WebJobs SDK are two different things even though their name is similar.

  • The WebJobs (without SDK) is a feature of Azure Websites. It is a generic, language/platform agnostic engine that can execute jobs. You can write jobs in many languages including: node, batch, C#/VB/any other .NET language
  • The WebJobs SDK is a framework, only for .NET, that simplifies the task of writing code that works with Azure Storage queues, blobs, and tables, and Service Bus queues; also, it is not tied to the WebJobs feature of Web Sites - it can run in any .NET application.

The JobHost is the entry point for the Azure WebJobs SDK. It is responsible for indexing, publishing, monitoring and scheduling the functions defined using WebJobs SDK artifacts. Whenever you want to invoke a WebJobs SDK function (triggered or manual/called) you need an instance of the JobHost. If your code doesn't require Azure Storage/ServiceBus or if you want to write all the polling/logging yourself, you don't need the Azure WebJobs SDK.

like image 97
Victor Hurdugaci Avatar answered Sep 19 '22 16:09

Victor Hurdugaci


You need the Jobs Host Configuration when you want to interact with Azure Storage (table storage, queues, blobs) or ServiceBus and if you want to expose your functions to the Azure WebJobs Dashboard.

This is some code I use in a WebJob that doesn't use JobHost

static ISubscriptions _subscriptions;

static void Main()
{
    Process();
}

public static void Process()
{
    _subscriptions.DoWork();
}
like image 20
lopezbertoni Avatar answered Sep 20 '22 16:09

lopezbertoni