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?
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 .
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.
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.
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.
WebJobs and WebJobs SDK are two different things even though their name is similar.
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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With