public static void ProcessQueueMessage([QueueTrigger("billingdatarequests")] BillingRequest br) { Console.WriteLine("Start webjob process. SubscriptionID: {0}", br.SubscriptionId); int retriesLeft = Convert.ToInt32(ConfigurationManager.AppSettings["ida:RetryCountToProcessMessage"].ToString()); while (retriesLeft > 0) { --retriesLeft; if (retriesLeft < 1) { Console.WriteLine("Finished internal retries, throwing exception. Time:{0}", DateTime.UtcNow.ToString()); throw new Exception(); } Console.WriteLine("Start time:{0} Retries Left: {1}", DateTime.UtcNow.ToString(), retriesLeft); try { //Fetch RateCard information First string rateCardURL = AzureResourceManagerUtil.GetRateCardRestApiCallURL(br.SubscriptionId, ConfigurationManager.AppSettings["ida:OfferCode"].ToString(), ConfigurationManager.AppSettings["ida:Currency"].ToString(), ConfigurationManager.AppSettings["ida:Locale"].ToString(), ConfigurationManager.AppSettings["ida:RegionInfo"].ToString()); Console.WriteLine("Request cost info from RateCard service."); RateCardPayload rateCardInfo = GetRateCardInfo(rateCardURL, br.OrganizationId); if (rateCardInfo == null) { Console.WriteLine("Problem receiving cost info occured - see log for details."); continue; } else { Console.WriteLine("Received cost info: " + rateCardInfo.ToString()); } // if granularity=hourly then report up to prev. hour, // if granularity=daily then report up to prev. day. Othervise will get 400 error //DateTime sdt = DateTime.Now.AddYears(-3); //DateTime edt = DateTime.Now.AddDays(-1); string restURL = AzureResourceManagerUtil.GetBillingRestApiCallURL(br.SubscriptionId, false, true, br.StartDate, br.EndDate); Console.WriteLine("Request usage data from Billing service."); List <UsageRecord> urs = GetUsageDetails(restURL, br.OrganizationId, rateCardInfo); Console.WriteLine("Received record count: {0}", urs.Count); Console.WriteLine("Insert usage data into SQL Server."); InsertIntoSQLDB(urs); break; } catch (Exception e) { Console.WriteLine("Exception: ProcessQueueMessage->e.Message: " + e.Message); if (retriesLeft == 0) { throw; } } Console.WriteLine("Sleeping in ProcessQueueMessage while loop for 5 min. DateTime: {0}", DateTime.Now.ToString()); Thread.Sleep(1000 * 60 * 5); } // while Commons.Utils.UpdateSubscriptionStatus(br.SubscriptionId, DataGenStatus.Completed, DateTime.UtcNow); Console.WriteLine("Complete webjob process. SubscriptionID: {0}", br.SubscriptionId); }