Ejemplo n.º 1
0
 public void Start()
 {
     _log.InfoFormat("Start consumer: {0} at queue {1}", "", _queueName);
     while (true)
     {
         try
         {
             _cancellationToken.ThrowIfCancellationRequested();
             JobCompanyCrawler jobCompany = GetJob();
             if (jobCompany != null)
             {
                 if (jobCompany.CheckRunning && CheckOtherRunning(jobCompany.CompanyId))
                 {
                     _log.Info(string.Format("Other running company: {0}", jobCompany));
                 }
                 else if (!_productAdapter.AllowCrawlReload(jobCompany.CompanyId))
                 {
                     _log.Info("Not allow crawler");
                     _redisWaitCrawler.DeleteWaitReload(new List <long> {
                         jobCompany.CompanyId
                     });
                 }
                 else
                 {
                     using (var worker = new WorkerReload(jobCompany.CompanyId, _nameThread))
                     {
                         worker.StartCrawler();
                     }
                 }
             }
             else
             {
                 _log.Info("No company to crawler");
                 Thread.Sleep(60000);
             }
         }
         catch (OperationCanceledException task)
         {
             break;
         }
         catch (Exception ex1)
         {
             _log.Error(ex1);
             Thread.Sleep(10000);
         }
     }
 }