public override void ProcessMessage(RabbitMQ.Client.Events.BasicDeliverEventArgs message) { ReportSessionRunning report = ReportSessionRunning.GetFromJson(message.Body); tracks.AddItem(report); this.GetChannel().BasicAck(message.DeliveryTag, true); }
public override void ProcessMessage(BasicDeliverEventArgs message) { var re = ReportSessionRunning.GetFromJson(message.Body); ReportToRedis(re); this.GetChannel().BasicAck(message.DeliveryTag, true); _log.Info("Saved sesionrunning"); }
public void AddItem(ReportSessionRunning item) { if (!dictionarySessionRunning.ContainsKey(item.Session)) { dictionarySessionRunning.Add(item.Session, item); } else { dictionarySessionRunning[item.Session] = item; } }
private void ReportToRedis(ReportSessionRunning re) { _redisWaitCrawler.SetRunningCrawler(re.CompanyId); if (re.Type == "Reload") { _redisWaitCrawler.SetNexReload(re.CompanyId, 1); } else if (re.Type == "FindNew") { _redisWaitCrawler.SetNexFindNew(re.CompanyId, 1); } }
private void FrmTrackRunning_Load(object sender, EventArgs e) { var token = _cancellationTokenSource.Token; Task.Factory.StartNew(() => { try { while (true) { if (!_stopRun) { token.ThrowIfCancellationRequested(); var rabbitMq = RabbitMQManager.GetRabbitMQServer(ConfigRun.KeyRabbitMqCrawler); var channel = rabbitMq.CreateChannel(); var job = channel.BasicGet("SeesionRunning.TrackRunning", true); if (job == null) { Thread.Sleep(1000); } else { ReportSessionRunning jobData = ReportSessionRunning.GetFromJson(job.Body); this.Invoke(new Action(() => { lstSessionRunnings.Add(jobData); })); } } else { Thread.Sleep(5000); } } } catch (OperationCanceledException ex) { return; } catch (Exception ex1) { } }, token); }
private void RunReportRunning() { var tokenReportSession = TokenSource.Token; Task.Factory.StartNew(() => { ProducerBasic producerReportSessionRunning = null; try { producerReportSessionRunning = new ProducerBasic(RabbitMQManager.GetRabbitMQServer(ConfigCrawler.KeyRabbitMqCrawler), ConfigCrawler.ExchangeSessionRunning, ConfigCrawler.RoutingkeySessionRunning); while (true) { tokenReportSession.ThrowIfCancellationRequested(); var mss = new ReportSessionRunning() { Thread = _nameThread, CompanyId = _companyId, Ip = Dns.GetHostName(), Session = _session, StartAt = _timeStart, Type = "Reload", MachineCode = Server.MachineCode }; producerReportSessionRunning.PublishString(Newtonsoft.Json.JsonConvert.SerializeObject(mss), true, 300); _log.Info(string.Format("Running Reload {0} {1} {2}'", this._companyId, (this._company != null) ? this._company.Domain : "", (DateTime.Now - this._timeStart).Minutes)); Thread.Sleep(60000); } } catch (OperationCanceledException ex) { _log.Info(string.Format("Stop reporting session:{0}", _session)); if (producerReportSessionRunning != null) { producerReportSessionRunning.Dispose(); } return; } catch (Exception ex01) { _producerReportError.PublishString(Newtonsoft.Json.JsonConvert.SerializeObject(new ErrorCrawler() { CompanyId = _companyId, ProductId = 0, TimeError = DateTime.Now, Message = ex01.Message + "\n" + ex01.StackTrace, Url = "" }), true, 0); } }, tokenReportSession); }