17

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?

Martin Prikryl
  • 147,050
  • 42
  • 335
  • 704
Emilio
  • 1,819
  • 3
  • 17
  • 24

2 Answers2

18

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.

Victor Hurdugaci
  • 27,343
  • 5
  • 83
  • 103
  • << 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. >> ...or if you want your methods to show up in the function dashboard. – Emilio Sep 13 '14 at 17:09
11

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();
}
Victor Hurdugaci
  • 27,343
  • 5
  • 83
  • 103
lopezbertoni
  • 3,146
  • 3
  • 36
  • 50
  • 1
    I also just found that the JobHost configuration is required if you want to expose your methods to the dashboard so you can invoke them. (See https://stackoverflow.com/questions/25811659/can-i-create-an-azure-webjob-that-exposes-functions-to-the-dashboard-but-doesnt). Just a suggestion: you might want to simplify your example to remove the first 3 lines under Main() because to someone new to Webjobs it might appear that your code is somehow Webjobs specific. Meaning, that you could significantly generalize & simplify your code example by simply only having Process() in Main. – Emilio Sep 12 '14 at 16:53
  • Also, if you update your answer to include the part about requiring a JobHost if you want to expose your methods to the dashboard for invocation, I will mark the answer as accepted. – Emilio Sep 12 '14 at 16:54