Esempio n. 1
0
        private void StartProcess(UserDatabase userDatabase)
        {
            var threadName = $"ThreadDbId{userDatabase.DatabaseId}";
            var count      = _databaseManager.ExecuteScalar(userDatabase.ConnectionString, "sc_calculation_queue_count");

            Common.Repository.IPricingRepository repo   = new Common.Repository.PricingRepository(userDatabase.ConnectionString, Constants.TIMEOUT_MSMQ_EXEC_STOREDPROC);
            Common.Engine.IPriceEngine           engine = new Common.Engine.PriceEngine(repo, Logger);

            if (count > this._appConfiguration.NewThreadMessages)
            {
                if (ActiveThreads.Count <= _appConfiguration.MaxThreadCount)
                {
                    if (this.ActiveThreads.All(t => t.Name != threadName))
                    {
                        var t = new Thread(() => Process(engine, userDatabase, count))
                        {
                            Name = threadName
                        };
                        t.Start();
                        ActiveThreads.Add(t);
                    }
                }
            }
            else
            {
                Process(engine, userDatabase, count);
            }
        }
Esempio n. 2
0
        public void Execute(int databaseId)
        {
            try
            {
                Logger.Info($"{GetType().Name} - [Common Background Tasks] Starting job for organization with database id: {databaseId}");
                //should get older background tasks with status new and one by one to try processing it before processing try to change status and after processing update status
                //processing itself should happen like listener.Process method

                var org = _orgManager.GetById(databaseId);
                if (!string.IsNullOrEmpty(org.ConnectionString))
                {
                    IBackgroundTaskManager taskManager = new BackgroundTaskManager(org.ConnectionString, Process.GetCurrentProcess().ProcessName);

                    var repo   = new Common.Repository.PricingRepository(org.ConnectionString, Constants.TIMEOUT_MSMQ_EXEC_STOREDPROC);
                    var engine = new PriceEngine(repo, Logger);

                    var tasks = taskManager.ListTasks(Fourth.StarChef.Invariables.Enums.BackgroundTaskStatus.New, null, null, false, 100, 0);
                    BackgroundTaskProcessor processor = new BackgroundTaskProcessor(databaseId, org.ConnectionString, _databaseManager, engine, Logger);

                    foreach (var t in tasks)
                    {
                        try
                        {
                            Logger.Info($"Task {t.Id} Processing");
                            var res = taskManager.UpdateTaskStatus(t.Id, t.Status, Fourth.StarChef.Invariables.Enums.BackgroundTaskStatus.InProgress, string.Empty).Result;
                            processor.ProcessMessage(t);
                            res = taskManager.UpdateTaskStatus(t.Id, Fourth.StarChef.Invariables.Enums.BackgroundTaskStatus.InProgress, Fourth.StarChef.Invariables.Enums.BackgroundTaskStatus.Completed, string.Empty).Result;
                            Logger.Info($"Task {t.Id} Processing Complete");
                        }
                        catch (Exception ex)
                        {
                            var res = taskManager.UpdateTaskStatus(t.Id, null, Fourth.StarChef.Invariables.Enums.BackgroundTaskStatus.Failed, ex.Message).Result;
                        }
                    }
                }
                else
                {
                    Logger.Warn($"OrganizationId {databaseId} not found");
                }

                Logger.Info($"{GetType().Name} - [Common Background Tasks] Finishing job for organization with database id: {databaseId}");
            }
            catch (Exception ex)
            {
                var errorMessage = new StringBuilder();
                errorMessage.AppendFormat($"{GetType().Name} - [Common Background Tasks] error for organization with database id: {databaseId} ");

                if (!string.IsNullOrEmpty(ex.Message))
                {
                    errorMessage.AppendFormat($"Exception message is: {ex.Message} ");
                }

                if (ex.InnerException != null && (!string.IsNullOrEmpty(ex.InnerException.Message)))
                {
                    errorMessage.AppendFormat($"Inner Exception message is: {ex.InnerException.Message}");
                }

                Logger.Error(errorMessage.ToString());
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            //var cnStr = "Initial Catalog=SCNET_Tish_Price_Test;Data Source=ie1scqaidb01.northeurope.cloudapp.azure.com;User ID=sl_web_user; Password=reddevil;";
            //var cnStr = "Initial Catalog=SCNET_trg;Data Source=ie1scqaidb01.northeurope.cloudapp.azure.com;User ID=sl_web_user; Password=reddevil;";
            //var cnStr = "Initial Catalog=SCNET_marstons;Data Source=ie1scqaidb01.northeurope.cloudapp.azure.com;User ID=sl_web_user; Password=reddevil;";
            //var cnStr = "Initial Catalog=SCNET_trg;Data Source=.\\sqlexpress;User ID=sl_web_user; Password=reddevil;";
            var cnStr = "Initial Catalog=SCNET_marstons;Data Source=.\\sqlexpress;User ID=sl_web_user; Password=reddevil;";

            //var t = new RecalculationTests(cnStr);
            //t.RecipePriceRecalculations();
            //return;

            Common.Repository.PricingRepository pr = new Common.Repository.PricingRepository(cnStr, 360);

            //var groupPrices2 = pr.GetGroupProductPricesByProduct(0, 455751, 0, 0, 0);
            //var prices = pr.GetPrices();
            IPriceEngine engine = new PriceEngine(pr);
            //var prices = engine.CalculatePrices(0, 152596, 0, 0, 0);
            //var prices = engine.CalculatePrices(0, 0, 0, 1, 0);
            //var prices = engine.CalculatePrices(0, 0, 0, 0, 369);
            var prices = engine.GlobalRecalculation(false, System.DateTime.UtcNow).Result;

            //var prices = engine.CalculatePrices(0, 0, 0, 0, 0).ToList();
            var taskPrices = pr.GetPrices().Result;
            var dbPrices   = taskPrices.OrderBy(x => x.ProductId).ToList();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            var priceToUpdate  = engine.ComparePrices(dbPrices, prices).ToList();
            var pricesToDelete = engine.ComparePrices(prices, dbPrices).ToList();

            sw.Stop();
            System.Diagnostics.Trace.WriteLine($"prices to update - {priceToUpdate.Count}");
            System.Diagnostics.Trace.WriteLine($"prices to delete - {pricesToDelete.Count}");
            System.Diagnostics.Trace.WriteLine($"Total Comparison time - {sw.Elapsed.TotalSeconds}");
        }