Reputation: 4144
I am receiving this error in my worker role:
Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (404) Not Found. ---> System.Net.WebException: The remote server returned an error: (404) Not Found. at System.Net.HttpWebRequest.GetResponse() at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](StorageCommandBase`1 cmd, IRetryPolicy policy, OperationContext operationContext) --- End of inner exception stack trace --- at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](StorageCommandBase`1 cmd, IRetryPolicy policy, OperationContext operationContext) at Microsoft.WindowsAzure.Storage.Queue.CloudQueue.DeleteMessage(String messageId, String popReceipt, QueueRequestOptions options, OperationContext operationContext) at Microsoft.WindowsAzure.Storage.Queue.CloudQueue.DeleteMessage(CloudQueueMessage message, QueueRequestOptions options, OperationContext operationContext) at CloudCartConnector.TaskRole2.WorkerRole.ExecuteTask() in C:\a\src\CCC\Source\CloudCartConnector.TaskRole2\WorkerRole.cs:line 101 Request Information RequestID:7a7c08ec-0003-0059-6d7b-2d118f000000 RequestDate:Thu, 03 Dec 2015 03:33:11 GMT StatusMessage:The specified queue does not exist. ErrorCode:QueueNotFound
If there was an exception in the on start method, would this cause a worker role to fail to run? Should I enter a try catch statement in the on start method and just return base.OnStart()? If my storage accounts becomes unavailable, due to a MS upgrade or a server going down, is the try catch the best?
public override bool OnStart()
{
ServicePointManager.DefaultConnectionLimit = 12;
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the queue client.
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
// Retrieve a reference to a queue.
queue = queueClient.GetQueueReference("taskqueue");
return base.OnStart();
}
Below this code, I execute a task. Should I say if the queue is null, just return?
public string GetTasks()
{
CloudQueueMessage cloudQueueMessasge = new CloudQueueMessage(message);
queue.AddMessage(cloudQueueMessasge, new TimeSpan(0, 30, 0));
}
catch (Exception ex)
{
return ex.ToString();
}
}
Upvotes: 1
Views: 9882
Reputation: 6255
You should have a try...catch
block in your OnStart method.
try{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the queue client.
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
// Retrieve a reference to a queue.
queue = queueClient.GetQueueReference("taskqueue");
}
catch(Microsoft.WindowsAzure.Storage.StorageException e)
{
// Exception Handling & Logging
// Return false for OnStart
}
You should also check if queue is null in your GetTasks()
method to prevent throwing potential and unnecessary NullReferenceException.
Upvotes: 3