Esempio n. 1
0
        protected override void OnStart(string[] args)
        {
            log.Info("Start service");
            try
            {
                InitializeComponent();
                cancelTokenSource = new CancellationTokenSource();
                string rabbitMQServerName = ConfigurationManager.AppSettings["rabbitMQ31ServerName"];
                workers        = new Worker[workerCount];
                rabbitMQServer = RabbitMQManager.GetRabbitMQServer(rabbitMQServerName);
                QT.Moduls.LogCassandra.LogCrawler logCass = new QT.Moduls.LogCassandra.LogCrawler();
                var db = new QT.Entities.Data.SqlDb(this.connectionString);
                for (int i = 0; i < workerCount; i++)
                {
                    log.InfoFormat("Start worker {i}", i.ToString());
                    var worker = new Worker(CrawlerProductLog, false, rabbitMQServer);
                    workers[i] = worker;
                    var  token      = this.cancelTokenSource.Token;
                    Task workerTask = new Task(() =>
                    {
                        worker.JobHandler = (updateDatafeedJob) =>
                        {
                            try
                            {
                                token.ThrowIfCancellationRequested();

                                QT.Entities.CrawlerProduct.RabbitMQ.MssLogCassandra mss = QT.Entities.CrawlerProduct.RabbitMQ.MssLogCassandra.GetDataFromMessage(updateDatafeedJob.Data);
                                logCass.SaveLogToCassandra(mss.log,
                                                           (QT.Moduls.LogCassandra.LogCode)mss.logCode,
                                                           (QT.Moduls.LogCassandra.TypeLog)mss.typeLog,
                                                           mss.data_id,
                                                           mss.data_second_id,
                                                           null,
                                                           mss.session);
                                log.InfoFormat("Log crawler company {0} : {1} ", mss.data_id, mss.data_second_id);
                                return(true);
                            }
                            catch (OperationCanceledException opc)
                            {
                                log.Info("End worker");
                                return(true);
                            }
                            catch (Exception ex01)
                            {
                                log.Info(ex01);
                                return(true);
                            }
                        };
                        worker.Start();
                    }, token);
                    workerTask.Start();
                    log.InfoFormat("Worker {0} started", i);
                }
            }
            catch (Exception ex)
            {
                log.Error("Start error", ex);
                throw;
            }
        }
Esempio n. 2
0
 protected override void OnStart(string[] args)
 {
     log.Info("Start service");
     try
     {
         InitializeComponent();
         cancelTokenSource = new CancellationTokenSource();
         string rabbitMQServerName = ConfigurationManager.AppSettings["rabbitMQServerName"];
         workers        = new Worker[workerCount];
         rabbitMQServer = RabbitMQManager.GetRabbitMQServer(rabbitMQServerName);
         QT.Moduls.LogCassandra.LogCrawler logCass = new QT.Moduls.LogCassandra.LogCrawler();
         for (int i = 0; i < workerCount; i++)
         {
             log.InfoFormat("Start worker {i}", i.ToString());
             var worker = new Worker(CrawlerProductLog, false, rabbitMQServer);
             workers[i] = worker;
             var  token      = this.cancelTokenSource.Token;
             Task workerTask = new Task(() =>
             {
                 worker.JobHandler = (updateDatafeedJob) =>
                 {
                     try
                     {
                         token.ThrowIfCancellationRequested();
                         QT.Entities.CrawlerProduct.RabbitMQ.MssLogFindNewProduct mss = QT.Entities.CrawlerProduct.RabbitMQ.MssLogFindNewProduct.GetDataFromMessage(updateDatafeedJob.Data);
                         logCass.LogFindNewProduct(mss.CRC, mss.Date_Log, mss.is_OK, mss.Product_ID, mss.Session, mss.Detail_Url);
                         return(true);
                     }
                     catch (OperationCanceledException opc)
                     {
                         log.Info("End worker");
                         return(true);
                     }
                     catch (Exception ex01)
                     {
                         log.Info(ex01);
                         return(true);
                     }
                 };
                 worker.Start();
             }, token);
             workerTask.Start();
             log.InfoFormat("Worker {0} started", i);
         }
     }
     catch (Exception ex)
     {
         log.Error("Start error", ex);
         throw;
     }
 }