Пример #1
0
        /// Timer trigger of CBProcessBPITrigger
        public static void CBProcessBPITrigger([TimerTrigger("0 5 12 * * *")] TimerInfo timer) // every day 12:05
        {
            try
            {
                Console.WriteLine("CB task timer starting at CBProcessBPITrigger");

                // send message to cloudbread-batch queue
                /// Azure Queue Storage connection retry policy
                var queueStorageRetryPolicy        = new ExponentialRetry(TimeSpan.FromSeconds(2), 10);
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ConnectionString);
                CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();
                queueClient.DefaultRequestOptions.RetryPolicy = queueStorageRetryPolicy;
                CloudQueue queue = queueClient.GetQueueReference("cloudbread-batch");

                /// send message to queue - Dormant
                CBBatchJob bj = new CBBatchJob();
                bj.JobID        = "CDBatch-BPI";
                bj.JobTitle     = "Best Purchased Item Batch";
                bj.JobTriggerDT = DateTimeOffset.UtcNow.ToString();
                bj.JobTrackID   = Guid.NewGuid().ToString();
                queue.AddMessage(new CloudQueueMessage(JsonConvert.SerializeObject(bj)));

                Console.WriteLine("CB task timer done at CBProcessBPITrigger");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        //////////////////////////////////////////////////////////////
        /// @brief Timer trigger of testProcess. one time test on startup and every two min(set it "0 */2 * * * *") . trigger
        //////////////////////////////////////////////////////////////
        public static void testProcess([TimerTrigger("0 */5 * * * *", RunOnStartup = true)] TimerInfo timer)
        {
            try
            {
                Console.WriteLine("CB test timer starting");

                CBBatchJob bj = new CBBatchJob();
                bj.JobID        = "test";
                bj.JobTitle     = "this is developer test job";
                bj.JobTriggerDT = DateTimeOffset.UtcNow.ToString();
                bj.JobTrackID   = Guid.NewGuid().ToString();

                /// send message to cloudbread-batch queue
                /// Azure Queue Storage connection retry policy
                var queueStorageRetryPolicy        = new ExponentialRetry(TimeSpan.FromSeconds(2), 10);
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ConnectionString);
                CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();
                queueClient.DefaultRequestOptions.RetryPolicy = queueStorageRetryPolicy;
                CloudQueue queue = queueClient.GetQueueReference("cloudbread-batch");
                queue.AddMessage(new CloudQueueMessage(JsonConvert.SerializeObject(bj)));

                Console.WriteLine("CB test timer done");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
        public static void CBProcessQueueMessage([QueueTrigger("cloudbread-batch")] CBBatchJob bj, int dequeueCount)
        {
            try
            {
                Console.WriteLine("CB task Starting {0} at CBProcessQueueMessage", bj.JobID);

                /// Database connection retry policy
                RetryPolicy retryPolicy = new RetryPolicy <SqlAzureTransientErrorDetectionStrategy>(CloudBreadconRetryCount, TimeSpan.FromSeconds(CloudBreadconRetryFromSeconds));

                switch (bj.JobID)
                {
                case "CDBatch-DAU":

                    using (SqlConnection connection = new SqlConnection(CBSchedulerDBConnectionString))
                    {
                        using (SqlCommand command = new SqlCommand("sspBatchDAU", connection))
                        {
                            connection.OpenWithRetry(retryPolicy);
                            command.ExecuteNonQueryWithRetry(retryPolicy);
                        }
                        connection.Close();
                    }
                    break;

                case "CDBatch-DARPU":

                    using (SqlConnection connection = new SqlConnection(CBSchedulerDBConnectionString))
                    {
                        using (SqlCommand command = new SqlCommand("sspBatchDARPU", connection))
                        {
                            connection.OpenWithRetry(retryPolicy);
                            command.ExecuteNonQueryWithRetry(retryPolicy);
                        }
                        connection.Close();
                    }
                    break;

                case "CDBatch-Dormant":

                    using (SqlConnection connection = new SqlConnection(CBSchedulerDBConnectionString))
                    {
                        using (SqlCommand command = new SqlCommand("sspBatchDormant", connection))
                        {
                            connection.OpenWithRetry(retryPolicy);
                            command.ExecuteNonQueryWithRetry(retryPolicy);
                        }
                        connection.Close();
                    }
                    break;

                case "CDBatch-DPA":

                    using (SqlConnection connection = new SqlConnection(CBSchedulerDBConnectionString))
                    {
                        using (SqlCommand command = new SqlCommand("sspBatchDPA", connection))
                        {
                            connection.OpenWithRetry(retryPolicy);
                            command.ExecuteNonQueryWithRetry(retryPolicy);
                        }
                        connection.Close();
                    }
                    break;

                case "CDBatch-DPU":

                    using (SqlConnection connection = new SqlConnection(CBSchedulerDBConnectionString))
                    {
                        using (SqlCommand command = new SqlCommand("sspBatchDPU", connection))
                        {
                            connection.OpenWithRetry(retryPolicy);
                            command.ExecuteNonQueryWithRetry(retryPolicy);
                        }
                        connection.Close();
                    }
                    break;

                case "CDBatch-FPC":

                    using (SqlConnection connection = new SqlConnection(CBSchedulerDBConnectionString))
                    {
                        using (SqlCommand command = new SqlCommand("sspBatchFPC", connection))
                        {
                            connection.OpenWithRetry(retryPolicy);
                            command.ExecuteNonQueryWithRetry(retryPolicy);
                        }
                        connection.Close();
                    }
                    break;

                case "CDBatch-FPU":

                    using (SqlConnection connection = new SqlConnection(CBSchedulerDBConnectionString))
                    {
                        using (SqlCommand command = new SqlCommand("sspBatchFPU", connection))
                        {
                            connection.OpenWithRetry(retryPolicy);
                            command.ExecuteNonQueryWithRetry(retryPolicy);
                        }
                        connection.Close();
                    }
                    break;

                case "CDBatch-MAU":

                    using (SqlConnection connection = new SqlConnection(CBSchedulerDBConnectionString))
                    {
                        using (SqlCommand command = new SqlCommand("sspBatchMAU", connection))
                        {
                            connection.OpenWithRetry(retryPolicy);
                            command.ExecuteNonQueryWithRetry(retryPolicy);
                        }
                        connection.Close();
                    }
                    break;

                case "CDBatch-MPU":

                    using (SqlConnection connection = new SqlConnection(CBSchedulerDBConnectionString))
                    {
                        using (SqlCommand command = new SqlCommand("sspBatchMPU", connection))
                        {
                            connection.OpenWithRetry(retryPolicy);
                            command.ExecuteNonQueryWithRetry(retryPolicy);
                        }
                        connection.Close();
                    }
                    break;

                case "CDBatch-WAU":

                    using (SqlConnection connection = new SqlConnection(CBSchedulerDBConnectionString))
                    {
                        using (SqlCommand command = new SqlCommand("sspBatchWAU", connection))
                        {
                            connection.OpenWithRetry(retryPolicy);
                            command.ExecuteNonQueryWithRetry(retryPolicy);
                        }
                        connection.Close();
                    }
                    break;

                case "CDBatch-WPU":

                    using (SqlConnection connection = new SqlConnection(CBSchedulerDBConnectionString))
                    {
                        using (SqlCommand command = new SqlCommand("sspBatchWPU", connection))
                        {
                            connection.OpenWithRetry(retryPolicy);
                            command.ExecuteNonQueryWithRetry(retryPolicy);
                        }
                        connection.Close();
                    }
                    break;

                case "CDBatch-BPI":

                    using (SqlConnection connection = new SqlConnection(CBSchedulerDBConnectionString))
                    {
                        using (SqlCommand command = new SqlCommand("sspBatchBPI", connection))
                        {
                            connection.OpenWithRetry(retryPolicy);
                            command.ExecuteNonQueryWithRetry(retryPolicy);
                        }
                        connection.Close();
                    }
                    break;

                case "CDBatch-HAU":

                    using (SqlConnection connection = new SqlConnection(CBSchedulerDBConnectionString))
                    {
                        using (SqlCommand command = new SqlCommand("sspBatchHAU", connection))
                        {
                            connection.OpenWithRetry(retryPolicy);
                            command.ExecuteNonQueryWithRetry(retryPolicy);
                        }
                        connection.Close();
                    }
                    break;

                case "test":
                    Console.WriteLine("CB test done {0} at CBProcessQueueMessage", bj.JobID);
                    break;

                default:
                    break;
                }

                Console.WriteLine("CB task done {0} at CBProcessQueueMessage", bj.JobID);

                string title = bj.JobID + " task done at " + bj.JobTriggerDT + ". track #" + bj.JobTrackID;
                string body  = "task info \n" + JsonConvert.SerializeObject(bj);

                /// send slack and email
                CBNotification.SendSlackMsg(CBNotiSlackChannel, title, CBNotiSlackUserName);
                // CBNotification.SendEmail(title, body);   /// TODO : setting on app.config?
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }