Reputation: 25080
I create an Azure WebJob as shown in the following script which dequeues an item from Azure Storage Queue, and then stores it to an Azure Table. The process is finished running within 1 or 2 seconds, but it runs only few a times in a minute (and occasionally halted in approximately 10 minutes). Overall, it does not work well.
What am I missing? Maybe I'm mixing trigger job and continuous job, but it is hard to find an appropriate sample.
class Program
{
static void Main(string[] args)
{
Console.WriteLine("started at {0}", DateTime.Now.ToString("s"));
// Continuous job should have infinite loop.
while(true){
var host = new JobHost();
host.RunAndBlock();
}
}
public static void ProcessQueueMessage([QueueInput("blogqueue")] string json)
{
var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings ["StorageConnectionString"].ConnectionString);
var tableClient = storageAccount.CreateCloudTableClient();
// Store it to Azure Table Storage
// omitted...
Console.WriteLine("Received JSON: {0}", json);
}
Upvotes: 2
Views: 9442
Reputation: 28425
A few comments:
while(true)
statement. RunAndBlock
already has a while loop inside and it will block there.Here is an example of binding to storage account:
public static void ProcessQueueMessage([QueueInput("blogqueue")] string json, CloudStorageAccount)
{
...
}
This is a wild guess but, from your code, it seems that the storage connection string is stored in StorageConnectionString
in the config file. The JobHost
expects either (1) the connection strings for runtime and data to be stored in AzureJobsData
and AzureJobsRuntime
(as described here) or (2) pass the connection string as parameter to the JobHost
constructor. I think this is the reason of the crash.
Upvotes: 6
Reputation: 6269
Just change your publish settings in ProjectName/Properties/webjob-publish-settings.json
"runMode": "OnDemand" => "runMode": "Continuous"
Upvotes: 4
Reputation: 9192
For a continuous WebJob to work properly you need to enable "Always On" in the configuration tab of your website.
The "Always On" feature is only offered for Basic/Standard website plan, if it is not enabled your WebJob can go down after some time.
Upvotes: 2