Exemple #1
0
        public static bool InsertMerchantShortInfoToCache(long merchantID, string productConnectionString, string userConnectionString)
        {
            var merchantShortInfo = MerchantBAL.GetMerchantShortInfo(merchantID, productConnectionString, userConnectionString);

            if (merchantShortInfo != null)
            {
                MerchantBAL.InsertMerchantShortInfoToCache(merchantShortInfo);
                return(true);
            }
            return(false);
        }
Exemple #2
0
        public static void InsertAllMerchantShortInfoToCache(string productConnectionString, string userConnectionString)
        {
            var startTime            = DateTime.Now;
            var allMerchantShortInfo = MerchantBAL.GetAllMerchantShortInfo(productConnectionString, userConnectionString);
            var getSqlDuration       = DateTime.Now - startTime;

            startTime = DateTime.Now;
            foreach (var merchantShortInfo in allMerchantShortInfo)
            {
                MerchantBAL.InsertMerchantShortInfoToCache(merchantShortInfo);
            }
            var insertDuration = DateTime.Now - startTime;

            Logger.InfoFormat("Insert {0} merchants, GetSQLTime: {1} second, InsertTime: {2} second", allMerchantShortInfo.Count, getSqlDuration.TotalSeconds, insertDuration.TotalSeconds);
        }
Exemple #3
0
        protected override void OnStart(string[] args)
        {
            try
            {
                var productConnectionString = ConfigurationManager.ConnectionStrings["productConnectionString"].ConnectionString;
                var userConnectionString    = ConfigurationManager.ConnectionStrings["userConnectionString"].ConnectionString;
                _productConnectionString = productConnectionString;
                _userConnectionString    = userConnectionString;
                string rabbitMQServerName = ConfigurationManager.AppSettings["rabbitMQServerName"];
                rabbitMQServer = RabbitMQManager.GetRabbitMQServer(rabbitMQServerName);
                string indexAllProductOfMerchantJobName     = ConfigurationManager.AppSettings["indexAllProductOfMerchantJobName"];
                int    indexAllProductOfMerchantWorkerCount = CommonUtilities.Object2Int(ConfigurationManager.AppSettings["indexAllProductOfMerchantWorkerCount"], 1);
                indexAllProductOfMerchantWorkers = new Worker[indexAllProductOfMerchantWorkerCount];
                string indexProductJobName     = ConfigurationManager.AppSettings["indexProductJobName"];
                int    indexProductWorkerCount = CommonUtilities.Object2Int(ConfigurationManager.AppSettings["indexProductWorkerCount"], 1);
                _searchEnginesServiceUrl = ConfigurationManager.AppSettings["searchEnginesServiceUrl"];
                indexProductWorkers      = new BatchWorker[indexProductWorkerCount];
                solrIndexer = new SolrIndexer();
                solrIndexer.ConnectionStringProducts = productConnectionString;
                solrIndexer.SolrClient = SolrProductClient.GetClient(SolrClientManager.GetSolrClient(SolrProductConstants.SOLR_NODE_PRODUCTS));
                _isRunning             = true;
                var updateDataTask = new Task(UpdateData);
                updateDataTask.Start();
                var updateListMerchantTask = new Task(UpdateListMerchant);
                updateListMerchantTask.Start();
                var updatePropertyTask = new Task(UpdateProperties);
                updatePropertyTask.Start();
                for (int i = 0; i < indexAllProductOfMerchantWorkerCount; i++)
                {
                    var worker = new Worker(indexAllProductOfMerchantJobName, false, rabbitMQServer);
                    indexAllProductOfMerchantWorkers[i] = worker;
                    var workerTask = new Task(() =>
                    {
                        Thread.Sleep(60000); //Sleep 90 seconds to wait for get Data Tasks;
                        worker.JobHandler = (indexAllProductOfMerchantJob) =>
                        {
                            var companyID = BitConverter.ToInt64(indexAllProductOfMerchantJob.Data, 0);
                            if (companyID == SolrIndexer.IDWebsosanh)
                            {
                                string message;
                                var numProducts = solrIndexer.UpdateAllRootProducts(out message, productConnectionString, userConnectionString, _searchEnginesServiceUrl);
                                if (numProducts < 0)
                                {
                                    return(false);
                                }
                                Logger.Debug("Update root products success!");
                                return(true);
                            }
                            else
                            {
                                var merchantInfo = MerchantBAL.GetMerchantShortInfoFromCache(companyID);
                                if (merchantInfo == null)
                                {
                                    merchantInfo = MerchantBAL.GetMerchantShortInfo(companyID, _productConnectionString, _userConnectionString);
                                    if (merchantInfo == null)
                                    {
                                        return(true);
                                    }
                                    MerchantBAL.InsertMerchantShortInfoToCache(merchantInfo);
                                }
                                var numProducts = solrIndexer.UpdateAllProductOfMerchant(companyID, merchantInfo.Domain);
                                if (numProducts < 0)
                                {
                                    return(false);
                                }
                                Logger.DebugFormat("Update company {0} success!", merchantInfo.Domain);
                                return(true);
                            }
                        };
                        worker.Start();
                    });
                    workerTask.Start();
                    Logger.InfoFormat("Update All products of Merchant Worker {0} started", i);
                }

                for (int i = 0; i < indexProductWorkerCount; i++)
                {
                    var worker = new BatchWorker(indexProductJobName, false, rabbitMQServer, 100, 300000);
                    indexProductWorkers[i] = worker;
                    var workerTask = new Task(() =>
                    {
                        Thread.Sleep(90000); //Sleep 90 seconds to wait for get Data Tasks;
                        worker.JobHandler = (indexProductJobs) =>
                        {
                            var merchantProductIds = new List <long>();
                            var rootProductIds     = new List <long>();
                            foreach (var indexProductJob in indexProductJobs)
                            {
                                var productID = BitConverter.ToInt64(indexProductJob.Data, 0);
                                if (indexProductJob.Type == 1)
                                {
                                    rootProductIds.Add(productID);
                                }
                                else
                                {
                                    merchantProductIds.Add(productID);
                                }
                            }
                            if (rootProductIds.Count > 0)
                            {
                                var startTime = DateTime.Now;
                                solrIndexer.UpdateRootProducts(rootProductIds, productConnectionString, userConnectionString, _searchEnginesServiceUrl);
                                Logger.DebugFormat("Update time : {0} ms - {1} rootProducts", (DateTime.Now - startTime).TotalMilliseconds, rootProductIds.Count);
                            }
                            else
                            {
                                var startTime = DateTime.Now;
                                solrIndexer.UpdateMerchantProducts(merchantProductIds);
                                Logger.DebugFormat("Update time : {0} ms - {1} merchantProducts", (DateTime.Now - startTime).TotalMilliseconds, merchantProductIds.Count);
                            }
                            return(true);
                        };
                        worker.Start();
                    });
                    workerTask.Start();
                    Logger.InfoFormat("Update Product Worker {0} started", i);
                }
            }
            catch (Exception excepion)
            {
                Logger.Error("Error on start", excepion);
                throw;
            }
        }
Exemple #4
0
        protected override void OnStart(string[] args)
        {
            try
            {
                var productConnectionString =
                    ConfigurationManager.ConnectionStrings["productConnectionString"].ConnectionString;
                MasOfferAdapter.SetConnection(productConnectionString);
                //WebMerchantProductCacheTool.InsertWebMerchantProductToCache(2642071820174507179,
                //"tiki.vn", productConnectionString);


                var    userConnecionString = ConfigurationManager.ConnectionStrings["userConnecionString"].ConnectionString;
                string rabbitMQServerName  = ConfigurationManager.AppSettings["rabbitMQServerName"];
                string updateAllProductOfMerchantToRedisJobName =
                    ConfigurationManager.AppSettings["updateAllProductOfMerchantToRedisJobName"];
                int updateAllProductOfMerchantWorkerCount =
                    CommonUtilities.Object2Int(
                        ConfigurationManager.AppSettings["updateAllProductOfMerchantWorkerCount"], 1);
                updateAllProductOfMerchantWorkers = new Worker[updateAllProductOfMerchantWorkerCount];
                string updateProductToRedisJobName = ConfigurationManager.AppSettings["updateProductToRedisJobName"];
                int    updateProductWorkerCount    =
                    CommonUtilities.Object2Int(ConfigurationManager.AppSettings["updateProductWorkerCount"], 1);
                var searchEnginesServiceUrl = ConfigurationManager.AppSettings["searchEnginesServiceUrl"];
                updateProductWorkers = new Worker[updateProductWorkerCount];
                rabbitMQServer       = RabbitMQManager.GetRabbitMQServer(rabbitMQServerName);

                for (int i = 0; i < updateAllProductOfMerchantWorkerCount; i++)
                {
                    var worker = new Worker(updateAllProductOfMerchantToRedisJobName, false, rabbitMQServer);
                    updateAllProductOfMerchantWorkers[i] = worker;
                    Task workerTask = new Task(() =>
                    {
                        worker.JobHandler = (updateAllProductOfMerchantToRedisJob) =>
                        {
                            try
                            {
                                var companyID = BitConverter.ToInt64(updateAllProductOfMerchantToRedisJob.Data, 0);
                                if (companyID == -1) //UpdateAlL
                                {
                                    WebMerchantProductCacheTool.InsertAllWebMerchantProductToCache(
                                        productConnectionString);
                                }
                                else if (companyID == 6619858476258121218) // Websosanh
                                {
                                    WebRootProductCacheTool.InsertAllWebRootProductIntoCache(productConnectionString,
                                                                                             userConnecionString, searchEnginesServiceUrl);
                                }
                                else
                                {
                                    var merchantShortInfo = MerchantBAL.GetMerchantShortInfoFromCache(companyID);
                                    if (merchantShortInfo == null)
                                    {
                                        merchantShortInfo = MerchantBAL.GetMerchantShortInfo(companyID,
                                                                                             productConnectionString, userConnecionString);
                                        if (merchantShortInfo == null)
                                        {
                                            return(false);
                                        }
                                        MerchantBAL.InsertMerchantShortInfoToCache(merchantShortInfo,
                                                                                   new TimeSpan(10000, 0, 0, 0, 0));
                                    }
                                    WebMerchantProductCacheTool.InsertWebMerchantProductToCache(companyID,
                                                                                                merchantShortInfo.Domain, productConnectionString);
                                }
                                return(true);
                            }
                            catch (Exception ex)
                            {
                                Logger.Error("Update All Products Of Merchant To Redis", ex);
                                return(false);
                            }
                        };
                        worker.Start();
                    });
                    workerTask.Start();
                    Logger.InfoFormat("Worker {0} started", i);
                }

                for (int i = 0; i < updateProductWorkerCount; i++)
                {
                    var worker = new Worker(updateProductToRedisJobName, false, rabbitMQServer);
                    updateProductWorkers[i] = worker;
                    Task workerTask = new Task(() =>
                    {
                        worker.JobHandler = (updateProductToRedisJob) =>
                        {
                            try
                            {
                                var productID = BitConverter.ToInt64(updateProductToRedisJob.Data, 0);
                                if (productID <= 0)
                                {
                                    Logger.WarnFormat("UpdateProductToRedis: Received productID {0}", productID);
                                    return(false);
                                }
                                if (updateProductToRedisJob.Type == 1) //RootProduct
                                {
                                    WebRootProductCacheTool.InsertWebRootProductIntoCache(productID,
                                                                                          productConnectionString, userConnecionString, searchEnginesServiceUrl);
                                }
                                else
                                {
                                    var webMerchantProduct = WebMerchantProductBAL.GetWebMerchantProduct(productID,
                                                                                                         productConnectionString);
                                    if (webMerchantProduct != null)
                                    {
                                        //XT: Change link if masOffer company
                                        MasOfferAdapter.SetConnection(productConnectionString);
                                        if (massOffer.CheckIsMasOffer(webMerchantProduct.CompanyID))
                                        {
                                            webMerchantProduct.DetailUrl =
                                                massOffer.GetFullUrl(webMerchantProduct.CompanyID,
                                                                     webMerchantProduct.DetailUrl);
                                        }

                                        WebMerchantProductBAL.InsertWebMerchantProductsIntoCache(new[]
                                                                                                 { webMerchantProduct });
                                    }
                                }
                                return(true);
                            }
                            catch (Exception ex)
                            {
                                Logger.Error("Update Product To Redis", ex);
                                return(false);
                            }
                        };
                        worker.Start();
                    });
                    workerTask.Start();
                    Logger.InfoFormat("Worker {0} started", i);
                }
            }
            catch (Exception excepion)
            {
                Logger.Error("Error on start", excepion);
                throw;
            }
        }