コード例 #1
0
        public static HttpResponseMessage Run(
            [HttpTrigger(AuthorizationLevel.Function, "get",
                         Route = "ProcessTabularModel/{databaseName}/tables/{tableList}")] HttpRequestMessage req,
            string databaseName,
            string tableList,
            TraceWriter log)
        {
            log.Info($"Received request to process the table - {databaseName}/{tableList}");

            try
            {
                SqlServerAnalysisServerTabular tabularModel = new SqlServerAnalysisServerTabular()
                {
                    ConnectionString = ConfigurationManager.ConnectionStrings["SsasTabularConnection"].ConnectionString,
                    DatabaseName     = databaseName ?? ConfigurationManager.AppSettings["DatabaseName"]
                };

                log.Info($"Starting table processing on {databaseName}/{tableList}");

                if (tableList.Contains(","))
                {
                    log.Info($"Multiple table processing requested.");

                    var tableNames = tableList.Split(',');
                    if (tableNames?.Length > 0)
                    {
                        log.Info($"Sending request to process {tableNames?.Length} tables in {databaseName}.");
                        tabularModel.ProcessTables(tableNames);
                    }
                }
                else
                {
                    log.Info($"Single table processing requested.");
                    tabularModel.ProcessTable(tableList);
                }
            }
            catch (Exception e)
            {
                log.Error($"Error occured processing {databaseName}/{tableList}. Details: {e.ToString()}", e);
                return(req.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }

            var successMessage = $"Successfully processed table - {databaseName}/{tableList}";

            log.Info(successMessage);
            return(req.CreateResponse(HttpStatusCode.OK, new { result = successMessage }));
        }
コード例 #2
0
        public static void Run([QueueTrigger("%ProcessTableQueue%", Connection = "AzureWebJobsStorage")] string myQueueItem,
                               [Table("%ProcessTableStatusTable%", Connection = "AzureWebJobsStorage")] CloudTable statusTable,
                               TraceWriter log)
        {
            log.Info($"Received queue trigger to process table : {myQueueItem}");

            QueueMessageProcesssTabular queueMessage = null;

            try
            {
                queueMessage = JsonConvert.DeserializeObject <QueueMessageProcesssTabular>(myQueueItem);

                int maximumRetries = int.TryParse(ConfigurationManager.AppSettings["MaximumRetries"], out maximumRetries) ?
                                     maximumRetries : 0;

                int waitTimeinSeconds = int.TryParse(ConfigurationManager.AppSettings["WaitTimeInSeconds"], out waitTimeinSeconds) ?
                                        waitTimeinSeconds : 30;

                RetryWaitPattern retryWaitPattern = Enum.TryParse <RetryWaitPattern>(ConfigurationManager.AppSettings["RetryWaitPattern"], out retryWaitPattern) ?
                                                    retryWaitPattern : RetryWaitPattern.Equal;


                SqlServerAnalysisServerTabular tabularModel = new SqlServerAnalysisServerTabular()
                {
                    ConnectionString = ConfigurationManager.ConnectionStrings["SsasTabularConnection"].ConnectionString,
                    DatabaseName     = queueMessage.Database ?? ConfigurationManager.AppSettings["DatabaseName"],
                    NumberOfRetries  = maximumRetries,
                    WaitPattern      = retryWaitPattern,
                    WaitTimeInSecondsBetweenRetries = waitTimeinSeconds
                };

                queueMessage.Status = "Running";
                queueMessage.ETag   = "*";
                TableOperation updateOperation = TableOperation.InsertOrReplace(queueMessage);
                statusTable.Execute(updateOperation);

                log.Info($"Starting table processing on {queueMessage.Database}/{queueMessage.Tables}");

                if (queueMessage.Tables.Contains(","))
                {
                    log.Info($"Multiple table processing requested.");

                    var tableNames = queueMessage.Tables.Split(',');
                    if (tableNames?.Length > 0)
                    {
                        log.Info($"Sending request to process {tableNames?.Length} tables in {queueMessage.Database}.");
                        tabularModel.ProcessTables(tableNames);
                    }
                }
                else
                {
                    log.Info($"Single table processing requested.");
                    tabularModel.ProcessTable(queueMessage.Tables);
                }

                queueMessage.Status = "Complete";
                queueMessage.ETag   = "*";
                updateOperation     = TableOperation.InsertOrReplace(queueMessage);
                statusTable.Execute(updateOperation);
            }
            catch (Exception e)
            {
                log.Error($"Error occured processing database table - {queueMessage?.Database}/{queueMessage?.Tables} : {e.ToString()}", e);
                queueMessage.Status       = "Error Processing";
                queueMessage.ErrorDetails = e.ToString();
                queueMessage.ETag         = "*";
                TableOperation updateOperation = TableOperation.InsertOrReplace(queueMessage);
                statusTable.Execute(updateOperation);
            }

            log.Info($"Completed table processing for {queueMessage?.Database}/{queueMessage?.Tables}");
        }