title: Calling method using Azure scheduled webjob
body: <p>I want to call my method using Azure webjobs as shown. But I want to run it every 5 mins from March 13th to March 20th for local test purposes. I have followed instructions as per this <a href="http://azure.microsoft.com/en-us/documentation/articles/websites-dotnet-webjobs-sdk-get-started/" rel="nofollow">article</a>. I have created test storage account and then added connection strings to app.config and web.config files. </p>
  
  <pre><code>class Program
  {
      static void Main()
      {
        var host = new JobHost();
        // The following code will invoke a function called ManualTrigger and 
        // pass in data (value in this case) to the function
        host.Call(typeof(Functions).GetMethod("GetStockAndStoreToDB"), new { value = 20 });   
        //host.RunAndBlock();
      }
  }
  </code></pre>
  
  <p>Here I want call my method GetStockAndStoreToDB.</p>
  
  <pre><code>public static void GetStockAndStoreToDB(TextWriter log, int value, [Queue("stockrequestqueue")] out string message)
  {
      log.WriteLine("Function is invoked with value={0}", value);
      message = value.ToString();
      bool dbUpdate = false;
      string[] symbolArray = { "Yahoo", "Google", "Microsoft"};
  
      foreach (string symbol in symbolArray)
      {
          //Get Stock at closing
          var returnStock = Helper.GetDailyStock(symbol);
          message = symbol.ToString();
          //Store it to the DB            
          dbUpdate = Helper.SetHistoricStockToDB(returnStock);
      }
      log.WriteLine("Following message will be written on the Queue={0}", message);
  }
  </code></pre>
  
  <p>And code for scheduled job (run every 5 minutues for test purpose only, once it starts working, I will change it to run daily once):</p>
  
  <pre><code>    {
          "$schema": "http://schemastore.org/schemas/json/webjob-publish-settings.json",
          "webJobName": "StockWebJob",
          "startTime": "2015-03-13T16:00:00-05:00",
          "endTime": "2015-03-20T16:00:00-05:00", 
          "jobRecurrenceFrequency": "Minute", //"Day"
          "interval": 5, //1
          "runMode": "Scheduled"
      }
  </code></pre>
  
  <p>In my controller:</p>
  
  <pre><code>    private CloudQueue stockRequestQueue;
  
      public StockController()
      {
          InitializeStorage();
      }
  
      private void InitializeStorage()
      {            
          // Open storage account using credentials from .cscfg file.
          var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ToString());
          //CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("AzureWebJobsStorage"));
  
          // Get context object for working with queues, and 
          // set a default retry policy appropriate for a web user interface.
          CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
          //queueClient.DefaultRequestOptions.RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(3), 3);
  
          // Get a reference to the queue.
          stockRequestQueue = queueClient.GetQueueReference("stockrequestqueue");
          // Create the queue if it doesn't already exist
          stockRequestQueue.CreateIfNotExists();
  
          // Create a message and add it to the queue.
          CloudQueueMessage queueMessage = new CloudQueueMessage("Get Stock");
          stockRequestQueue.AddMessage(queueMessage);
      }
  </code></pre>
  
  <p>Please advice me where I am doing wrong, since the console creates once and stops, it doesn't run every 5 mins. If I use host.RunAndBlock(); then the console is open but it doesn't run anything.</p>