Ejemplo n.º 1
0
Archivo: Job.cs Proyecto: c0d3m0nky/mty
 public void Cancel(IJobRepository jobRepository,Event dblogEvent)
 {
     jobRepository.CancelJob(this, dblogEvent.Monitor == Event.Monitors.CancelOnBulking ? CobCancelCode : F21CancelCode);
     dblogEvent.EventActions.Add(new EventAction()
     {
         Action = EventAction.Actions.JobCancel,
         ActedOnDeliveryGroupId = deliverygroup_id,
         JobId = job_id
     });
 }
Ejemplo n.º 2
0
        public static void CancelHotmailJobsByDeliveryGroup(IJobRepository jobRepository, ILog logger, DeliveryGroup deliveryGroup, DateTime cutOffTime, Event dblogEvent)
        {
            var jobs = jobRepository.GetAll().Where(j => j.deliverygroup_id == deliveryGroup.deliverygroup_id
                                                            && j.datelaunch < cutOffTime
                                                            && j.DeliveryGroup.CancelOnBulkingEnabled
                                                            && !CancellationExcludedJobStatusIds.Contains(j.jobstatus_id)).ToArray();

            foreach (var job in jobs)
            {
                job.Cancel(jobRepository,dblogEvent);
                logger.InfoFormat("Cancelled Job {0} and its targets", job.job_id);
            }
            logger.InfoFormat("Cancelled {0} Jobs", jobs.Count());
        }
Ejemplo n.º 3
0
        public virtual void SendEvent(Event dblogEvent)
        {
            var smtp = new SmtpClient(_smtpserver);
            var email = new MailMessage
            {
                From = new MailAddress("*****@*****.**"),
                Body = GetHtml(dblogEvent),
                IsBodyHtml = true,
                Subject = GetSubject(dblogEvent.Monitor, dblogEvent.EventName)
            };

            _emailAddresses.ToList().ForEach(a => email.To.Add(a));
            smtp.Send(email);
        }
Ejemplo n.º 4
0
 private string GetSubject(Event.Monitors monitor, Event.EventNames eventNames)
 {
     switch (eventNames)
     {
         case Event.EventNames.SomeBulked:
             return "COB: Some campaigns for a DVG are bulking";
         case Event.EventNames.AllBulked:
             return "COB: All campaigns for a DVG are bulking";
         case Event.EventNames.ResetTime:
             return monitor == Event.Monitors.CancelOnBulking ? "COB: Mta Queues Reset" : "421: Mta Queues Reset";
         case Event.EventNames.FourthBackOff:
             return "421: 4th 421 for Queue";
         default:
             return "PMTA Monitor Notification";
     }
 }
Ejemplo n.º 5
0
Archivo: Job.cs Proyecto: c0d3m0nky/mty
        public static void CancelHotmailRelatedJobs(IJobRepository jobRepository, ILog logger, Campaign campaign, DateTime cutOffTime, Event dblogEvent)
        {
            var jobs = jobRepository.GetAll()
                          .Where(j => j.Template.creative_id == campaign.Template.creative_id
                                      && j.Template.fromName.Trim() == campaign.Template.fromName.Trim()
                                      && j.Template.emailSubject.Trim() == campaign.Template.emailSubject
                                      && !CancellationExcludedJobStatusIds.Contains(j.jobstatus_id)
                                      && j.deliverygroup_id.HasValue
                                      && j.DeliveryGroup.CancelOnBulkingEnabled
                                      && j.datelaunch < cutOffTime).ToArray();

            foreach (var j in jobs)
            {
                j.Cancel(jobRepository,dblogEvent);
                logger.TraceFormat("Cancelled Job {0} and its targets", j.job_id);
            }
            logger.InfoFormat("Cancelled {0} Jobs", jobs.Count());
        }
Ejemplo n.º 6
0
        private void ResetFourthBackoff(
            Pmta pmta,
            Event currentEvent,
            Event resetEvent,
            DateTime resetTime,
            IDeliveryGroupRepository deliveryGroupRepository,
            IJobRepository jobRepository
            )
        {
            IEnumerable<string> queues;

            lock (_locker)
            {
                queues = resetEvent.EventActions.Where(ed => ed.PmtaId == pmta.PmtaId && ed.PmtaQueue != null).Select(ed => ed.PmtaQueue).Distinct().ToArray();
            }

            foreach (var queue in queues)
            {
                if (!_mtaAgent.IsQueueActive(pmta.ToMta(), queue))
                {
                    _mtaAgent.Purge(pmta.ToMta(), queue);
                    _logger.InfoFormat("Purged {0} on {1}", queue, pmta.Host);

                    lock (_locker)
                    {
                        currentEvent.EventActions.Add(new EventAction()
                                                    {
                                                        Action = EventAction.Actions.MTAPurge,
                                                        Pmta = pmta,
                                                        PmtaQueue = queue
                                                    });

                        var deliveryGroup = DeliveryGroup.GetByVmta(pmta, queue, deliveryGroupRepository);

                        if (deliveryGroup != null)
                        {
                            DeliveryGroup.CancelHotmailJobsByDeliveryGroup(jobRepository, _logger, deliveryGroup, resetTime, currentEvent);
                        }
                    }

                    _mtaAgent.UnPause(pmta.ToMta(), queue);
                    _logger.InfoFormat("Resumed {0} on {1}", queue, pmta.Host);

                    lock (_locker)
                    {
                        currentEvent.EventActions.Add(new EventAction()
                                                    {
                                                        Action = EventAction.Actions.ResumedQueue,
                                                        Pmta = pmta,
                                                        PmtaQueue = queue
                                                    });
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void ResumePmtaQueues(
            Pmta pmta,
            Event dbLogEvent,
            DateTime resetTime,
            IUnitOfWork unitOfWork,
            IEventRepository eventRepository,
            IDeliveryGroupRepository deliveryGroupRepository,
            IJobRepository jobRepository
            )
        {
            IEnumerable<Event> events;
            IGrouping<string, Event>[] eventGroups;

            lock (_locker)
            {
                var qEvents = Event.GetEventsToReset(eventRepository, Event.Monitors.Four21);
                var actions = qEvents.SelectMany(e => e.EventActions.Where(a => a.PmtaId == pmta.PmtaId).Select(a => new { a.PmtaQueue, a.EventId }).Distinct());

                eventGroups = (from e in qEvents
                               join a in actions on e.EventId equals a.EventId
                               group e by a.PmtaQueue
                                   into eg
                                   select eg).ToArray();
                events = qEvents.ToArray();
            }

            foreach (var group in eventGroups)
            {
                var lastEvent = group.OrderByDescending(g => g.DateCreated).First();

                switch (lastEvent.EventName)
                {
                    case Event.EventNames.SecondBackOff:
                        _logger.InfoFormat("Resuming Event {0}", lastEvent.EventId);
                        ResumeSecondBackOff(lastEvent, unitOfWork, jobRepository, eventRepository, deliveryGroupRepository, dbLogEvent);
                        break;
                    case Event.EventNames.FourthBackOff:
                        _logger.InfoFormat("Resetting Event {0}", lastEvent.EventId);
                        ResetFourthBackoff(pmta, dbLogEvent, lastEvent, resetTime, deliveryGroupRepository, jobRepository);
                        break;
                }

            }

            foreach (var resetEvent in events)
            {
                resetEvent.ResetEventId = dbLogEvent.EventId;
            }

            lock (_locker)
            {
                unitOfWork.SaveChanges();
            }

        }
Ejemplo n.º 8
0
        public void FindAndCancelBulkingCampaigns(
            IPmtaRepository pmtaRepository,
            IDeliveryGroupRepository deliveryGroupRepository,
            IHeatDataRepository heatDataRepository,
            int heatDataLookBackMinutes,
            int minimumRecords,
            int minimumInboxing,
            DateTime nextReset
            )
        {
            _logger.Info("Getting Heat Data");
            var inboxing = heatDataRepository.GetCampaignInboxingStatistics(heatDataLookBackMinutes).ToArray();

            _logger.Info("Getting DeliveryGroups");
            var monitoredDeliveryGroups = DeliveryGroup.GetMonitored(deliveryGroupRepository).ToArray();

            _logger.Info("Verifying Pmtas for Monitored DeliverGroups");
            var deliveryServerIds = Pmta.GetDeliveryServerIdsForMonitoredDeliveryGroups(pmtaRepository, deliveryGroupRepository);
            var pmtas = pmtaRepository.GetAll();
            var missingPmtas = deliveryServerIds.Where(d => !pmtas.Any(p => p.deliveryserver_id == d));

            if (missingPmtas.Any())
            {
                _logger.WarnFormat("Missing Pmtas for DeliveryServers {0}", string.Join(", ", missingPmtas));
                return;
            }
            
            foreach (var deliveryGroup in monitoredDeliveryGroups)
            {
                try
                {
                    var campaigns = inboxing.Where(c => c.Records >= minimumRecords && c.DeliveryGroups.Any(d => d.deliverygroup_id == deliveryGroup.deliverygroup_id)).ToArray();

                    if (campaigns.Any())
                    {
                        var bulkingCampaignsStats = campaigns.Where(c => c.InboxingRate <= minimumInboxing).ToArray();

                        if (bulkingCampaignsStats.Count() == campaigns.Count())
                        {
                            var dblogEvent = new Event()
                            {
                                EventName = Event.EventNames.AllBulked,
                                DeliveryGroup = deliveryGroup,
                                Monitor = Event.Monitors.CancelOnBulking,
                                InboxingRateSetting = minimumInboxing
                            };

                            bulkingCampaignsStats.Select(c => new EventCampaign() { Campaign = c.Campaign, InboxingRate = c.InboxingRate })
                                .ToList().ForEach(c => dblogEvent.EventCampaigns.Add(c));

                            _eventRepository.Add(dblogEvent);
                            _logger.InfoFormat("Starting AllBulked on {0}", deliveryGroup.deliverygroup_id);
                            _unitOfWork.SaveChanges();

                            PausePurgeAndCancelByDeliveryGroup(pmtaRepository, nextReset, deliveryGroup, dblogEvent);

                            _emailNotification.SendEvent(dblogEvent);
                        }
                        else if (bulkingCampaignsStats.Any())
                        {
                            var dblogEvent = new Event()
                            {
                                EventName = Event.EventNames.SomeBulked,
                                DeliveryGroup = deliveryGroup,
                                Monitor = Event.Monitors.CancelOnBulking,
                                InboxingRateSetting = minimumInboxing
                            };

                            bulkingCampaignsStats.Select(c => new EventCampaign() { Campaign = c.Campaign, InboxingRate = c.InboxingRate })
                                .ToList().ForEach(c => dblogEvent.EventCampaigns.Add(c));

                            _eventRepository.Add(dblogEvent);
                            _logger.InfoFormat("Starting SomeBulked on {0}", deliveryGroup.deliverygroup_id);
                            _unitOfWork.SaveChanges();

                            foreach (var campaignStats in bulkingCampaignsStats)
                            {
                                if (campaignStats.Campaign.Template.creative_id.HasValue)
                                {
                                    PurgeAndCancelByCampaignContent(pmtaRepository, nextReset, campaignStats, deliveryGroupRepository, dblogEvent);
                                }
                            }
                            _emailNotification.SendEvent(dblogEvent);
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorFormat("DVG {0}: {1}", deliveryGroup.deliverygroup_id, ex.UnwrapForLog(true));
                }
            }
        }
Ejemplo n.º 9
0
        private string GetFourthBackOffHtml(Event dblogEvent)
        {
            StreamReader streamReader;
            StringBuilder template;
            string jobSubTemplate;

            lock (_locker)
            {
                streamReader = File.OpenText(Path.Combine(_baseDir, FourthBackOffTemplateFileName));
                template = new StringBuilder(streamReader.ReadToEnd());
                streamReader.Close();
                streamReader = File.OpenText(Path.Combine(_baseDir, JobsSubTemplateFileName));
                jobSubTemplate = streamReader.ReadToEnd();
                streamReader.Close();
            }

            var eventDetail = dblogEvent.EventActions.First(ed => ed.Action == EventAction.Actions.MTAPause);

            template.Replace("{Queue}", eventDetail.PmtaQueue);
            template.Replace("{Pmta}", eventDetail.Pmta.Host);

            var jobSection = new StringBuilder();
            var cancelActions = dblogEvent.EventActions.Where(ed => ed.Action == EventAction.Actions.JobCancel).ToArray();

            if (cancelActions.Any())
            {
                foreach (var job in cancelActions)
                {
                    jobSection.AppendLine(jobSubTemplate);
                    jobSection.Replace("{JobId}", job.JobId.ToString());
                }
            }
            else
            {
                jobSection.AppendLine("No jobs cancelled");
            }

            template.Replace("{JobsCancelled}", jobSection.ToString());

            return template.ToString();

        }
Ejemplo n.º 10
0
        private void ProcessSecondBackOff(
            Pmta pmta,
            string queue,
            Event lastEvent,
            IUnitOfWork unitOfWork,
            IEventRepository eventRepository
            )
        {
            _logger.InfoFormat("Second Back Off for {0} on {1}", queue, pmta.Host);

            Event dbLogEvent = eventRepository.Add(new Event()
                                                   {
                                                       EventName = Event.EventNames.SecondBackOff,
                                                       Monitor = Event.Monitors.Four21,
                                                       SeriesId = lastEvent.SeriesId
                                                   });

            _mtaAgent.Pause(pmta.ToMta(), queue);
            _logger.InfoFormat("Paused {0} on {1}", queue, pmta.Host);

            dbLogEvent.EventActions.Add(new EventAction()
                {
                    Action = EventAction.Actions.MTAPause,
                    Pmta = pmta,
                    PmtaQueue = queue
                });

            _mtaAgent.RemoveBackoff(pmta.ToMta(), queue);
            _logger.InfoFormat("Removed Back Off from {0} on {1}", queue, pmta.Host);

            dbLogEvent.EventActions.Add(new EventAction()
                {
                    Action = EventAction.Actions.RemoveBackOff,
                    Pmta = pmta,
                    PmtaQueue = queue
                });

            _mtaAgent.Purge(pmta.ToMta(), queue);
            _logger.InfoFormat("Purged {0} on {1}", queue, pmta.Host);

            dbLogEvent.EventActions.Add(new EventAction()
            {
                Action = EventAction.Actions.MTAPurge,
                Pmta = pmta,
                PmtaQueue = queue
            });

            lock (_locker)
            {
                unitOfWork.SaveChanges();
            }
        }
Ejemplo n.º 11
0
        private void PurgeAndCancelByCampaignContent(IPmtaRepository pmtaRepository, DateTime nextReset, CampaignInboxingStatistics campaignStats, IDeliveryGroupRepository deliveryGroupRepository, Event dblogEvent)
        {
            var jobs = Job.GetHotmailRelatedJobsSent(_jobRepository, campaignStats.Campaign, nextReset).ToArray();
            var dvgs = (from d in DeliveryGroup.GetMonitored(deliveryGroupRepository).ToArray()
                        where jobs.Select(j => j.deliverygroup_id.Value)
                                  .Distinct()
                                  .Contains(d.deliverygroup_id)
                        select new { Id = d.deliverygroup_id, Pmtas = Pmta.GetPmtasByDeliveryGroup(pmtaRepository, d).ToArray() }).ToArray();
            var mtaEventDetails = new List<EventAction>();

            var mtaJobDeleteTask = new Task(() =>
                              {
                                  var commandsSent = 0;
                                  _logger.DebugFormat("Deleting Related Jobs from MTAs");
                                  foreach (var job in jobs)
                                  {
                                      try
                                      {
                                          var pmtas = dvgs.FirstOrDefault(d => d.Id == job.deliverygroup_id.Value).Pmtas;

                                          if (pmtas.Any())
                                          {
                                              foreach (var pmta in pmtas)
                                              {
                                                  _mtaAgent.DeleteJob(pmta.ToMta(), job.job_id);
                                                  commandsSent++;
                                              }
                                          }
                                          else
                                          {
                                              _logger.TraceFormat("No DeliveryServers found for DeliveryGroup {0}", job.deliverygroup_id);
                                          }

                                          mtaEventDetails.Add(new EventAction()
                                          {
                                              Action = EventAction.Actions.MTAJobDelete,
                                              ActedOnDeliveryGroupId = job.deliverygroup_id,
                                              JobId = job.job_id
                                          });
                                      }
                                      catch (Exception ex)
                                      {
                                          _logger.ErrorFormat("Job {0}: {1}", job.job_id, ex.UnwrapForLog(true));
                                      }
                                  }
                                  _logger.DebugFormat("Sent {0} delete commands for {1} Jobs to MTAs", commandsSent, jobs.Count());
                              });

            try
            {
                mtaJobDeleteTask.Start();

                try
                {
                    _logger.DebugFormat("Cancelling Related Jobs");
                    Job.CancelHotmailRelatedJobs(_jobRepository, _logger, campaignStats.Campaign, nextReset, dblogEvent);
                }
                catch (Exception ex)
                {
                    _logger.ErrorFormat("Campaign {0}: {1}", campaignStats.Campaign.campaign_id, ex.UnwrapForLog(true));
                }

                mtaJobDeleteTask.Wait();
            }
            catch (AggregateException ex)
            {
                foreach (var innerException in ex.InnerExceptions)
                {
                    _logger.Error(innerException.UnwrapForLog(false));
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.UnwrapForLog());
            }

            mtaEventDetails.ForEach(e => dblogEvent.EventActions.Add(e));

            _unitOfWork.SaveChanges();
        }
Ejemplo n.º 12
0
        private string GetResetHtml(Event dblogEvent)
        {
            StringBuilder template;
            string queueSubTemplate;
            string jobSubTemplate;

            lock (_locker)
            {
                StreamReader streamReader = File.OpenText(Path.Combine(_baseDir, ResetTemplateFileName));
                template = new StringBuilder(streamReader.ReadToEnd());
                streamReader.Close();
                streamReader = File.OpenText(Path.Combine(_baseDir, QueuesSubTemplateFileName));
                queueSubTemplate = streamReader.ReadToEnd();
                streamReader.Close();
                streamReader = File.OpenText(Path.Combine(_baseDir, JobsSubTemplateFileName));
                jobSubTemplate = streamReader.ReadToEnd();
                streamReader.Close();
            }

            template.Replace("{Monitor}", dblogEvent.Monitor == Event.Monitors.CancelOnBulking ? "COB" : "421");

            template.Replace("{Event.DateCreated}", dblogEvent.DateCreated.ToString("yyyy-MM-dd HH:mm:ss.f"));

            var queueSection = new StringBuilder();

            if (dblogEvent.EventActions.Any())
            {
                foreach (var queue in dblogEvent.EventActions)
                {
                    queueSection.AppendLine(queueSubTemplate);
                    queueSection.Replace("{Queue}", queue.PmtaQueue);
                    queueSection.Replace("{Host}", queue.Pmta.Host);
                }
            }
            else
            {
                queueSection.AppendLine(queueSubTemplate);
                queueSection.Replace("{Queue}", "No Queues to Restart");
                queueSection.Replace("{Host}", "");
            }

            template.Replace("{Queues}", queueSection.ToString());

            if (dblogEvent.Monitor == Event.Monitors.CancelOnBulking)
            {
                template.Replace("{JobsCancelled}", "");
            }
            else
            {
                var jobSection = new StringBuilder();
                var cancelActions = dblogEvent.EventActions.Where(ed => ed.Action == EventAction.Actions.JobCancel).ToArray();

                if (cancelActions.Any())
                {
                    foreach (var job in cancelActions)
                    {
                        jobSection.AppendLine(jobSubTemplate);
                        jobSection.Replace("{JobId}", job.JobId.ToString());
                    }
                }
                else
                {
                    jobSection.AppendLine("No jobs cancelled");
                }

                template.Replace("{JobsCancelled}", jobSection.ToString());
            }

            return template.ToString();

        }
Ejemplo n.º 13
0
        private string GetDVGCancelHtml(Event dblogEvent)
        {
            StringBuilder template;

            lock (_locker)
            {
                StreamReader streamReader = File.OpenText(Path.Combine(_baseDir, DVGCancelTemplateFileName));
                template = new StringBuilder(streamReader.ReadToEnd());
                streamReader.Close();
            }

            template.Replace("{DVGName}", dblogEvent.DeliveryGroup != null ? dblogEvent.DeliveryGroup.groupName : dblogEvent.DeliveryGroupId.ToString());
            template.Replace("{minimumInboxing}", dblogEvent.InboxingRateSetting.ToString());

            var jobIds = dblogEvent.EventActions.Where(ed => ed.Action == EventAction.Actions.JobCancel && ed.JobId.HasValue).Select(ed => ed.JobId.Value).ToArray();

            IEnumerable<NotificationCampaign> campaigns = null;

            lock (_locker)
            {
                var jobs = (from j in _jobRepository.GetAll()
                            where jobIds.Contains(j.job_id)
                            select new
                                   {
                                       j.campaign_id,
                                       j.job_id
                                   }
                                ).ToArray();

                campaigns = from j in jobs
                            join ec in dblogEvent.EventCampaigns.ToArray() on j.campaign_id equals ec.CampaignId
                            group j by ec
                                into jg
                                select new NotificationCampaign()
                                       {
                                           Id = jg.Key.CampaignId,
                                           InboxingRate = jg.Key.InboxingRate,
                                           JobIds = jg.Select(jj => jj.job_id),
                                           Name = jg.Key.Campaign.campaignName
                                       };
            }

            template.Replace("{Campaigns}", RenderCampaigns(campaigns, true));


            return template.ToString();

        }
Ejemplo n.º 14
0
        private string GetContentCancelHtml(Event dblogEvent)
        {
            StringBuilder template;

            lock (_locker)
            {
                StreamReader streamReader = File.OpenText(Path.Combine(_baseDir, ContentCancelTemplateFileName));
                template = new StringBuilder(streamReader.ReadToEnd());
                streamReader.Close();
            }

            template.Replace("{DVGName}", dblogEvent.DeliveryGroup != null ? dblogEvent.DeliveryGroup.groupName : dblogEvent.DeliveryGroupId.ToString());
            template.Replace("{minimumInboxing}", dblogEvent.InboxingRateSetting.ToString());


            try
            {
                template.Replace("{BulkingCampaigns}", RenderCampaigns(dblogEvent.EventCampaigns.Select(e => new NotificationCampaign()
                                                                                                               {
                                                                                                                   Id = e.CampaignId,
                                                                                                                   InboxingRate = e.InboxingRate,
                                                                                                                   Name = e.Campaign.campaignName
                                                                                                               }), false));
            }
            catch (Exception ex)
            {
                _logger.Fatal(ex.UnwrapForLog(true));
            }

            IEnumerable<NotificationCampaign> affectedCampaigns = null;

            lock (_locker)
            {
                affectedCampaigns = (from j in _jobRepository.GetAll()
                                     join ej in dblogEvent.EventActions.Where(ed => ed.Action == EventAction.Actions.JobCancel)
                                                          .Select(ed => ed.JobId) on j.job_id equals ej
                                     group j by j.Campaign
                                         into gj
                                         select new NotificationCampaign()
                                                {
                                                    Id = gj.Key.campaign_id,
                                                    JobIds = gj.Select(j => j.job_id),
                                                    Name = gj.Key.campaignName
                                                }).ToArray();
            }

            template.Replace("{AffectedCampaigns}", RenderCampaigns(affectedCampaigns, true));

            return template.ToString();
        }
Ejemplo n.º 15
0
        private void ProcessFourthBackOff(
            Pmta pmta,
            string queue,
            Event lastEvent,
            DateTime nextReset,
            IUnitOfWork unitOfWork,
            IJobRepository jobRepository,
            IEventRepository eventRepository,
            IDeliveryGroupRepository deliveryGroupRepository
            )
        {
            _logger.InfoFormat("Fourth Back Off for {0} on {1}", queue, pmta.Host);

            var dbLogEvent = eventRepository.Add(new Event()
            {
                EventName = Event.EventNames.FourthBackOff,
                Monitor = Event.Monitors.Four21,
                SeriesId = lastEvent.SeriesId
            });

            _mtaAgent.Pause(pmta.ToMta(), queue);
            _logger.InfoFormat("Paused {0} on {1}", queue, pmta.Host);

            dbLogEvent.EventActions.Add(new EventAction()
                {
                    Action = EventAction.Actions.MTAPause,
                    Pmta = pmta,
                    PmtaQueue = queue
                });

            _mtaAgent.RemoveBackoff(pmta.ToMta(), queue);
            _logger.InfoFormat("Removed Back Off from {0} on {1}", queue, pmta.Host);

            dbLogEvent.EventActions.Add(new EventAction()
                {
                    Action = EventAction.Actions.RemoveBackOff,
                    Pmta = pmta,
                    PmtaQueue = queue
                });

            _mtaAgent.Purge(pmta.ToMta(), queue);
            _logger.InfoFormat("Purged {0} on {1}", queue, pmta.Host);

            dbLogEvent.EventActions.Add(new EventAction()
            {
                Action = EventAction.Actions.MTAPurge,
                Pmta = pmta,
                PmtaQueue = queue
            });

            lock (_locker)
            {
                var deliveryGroup = DeliveryGroup.GetByVmta(pmta, queue, deliveryGroupRepository);

                if (deliveryGroup != null)
                {
                    DeliveryGroup.CancelHotmailJobsByDeliveryGroup(jobRepository, _logger, deliveryGroup, nextReset, dbLogEvent);
                }

                unitOfWork.SaveChanges();
            }

            _emailNotification.SendEvent(dbLogEvent);

        }
Ejemplo n.º 16
0
        private void PausePurgeAndCancelByDeliveryGroup(IPmtaRepository pmtaRepository, DateTime nextReset, DeliveryGroup deliveryGroup, Event dblogEvent)
        {
            foreach (var deliveryServer in Pmta.GetVmtasGroupedByDeliveryServerForDeliveryGroup(pmtaRepository, deliveryGroup))
            {
                try
                {
                    var pmta = pmtaRepository.GetAll().FirstOrDefault(p => p.deliveryserver_id == deliveryServer.Key);

                    if (pmta != null)
                    {
                        var queues = _mtaAgent.GetHotmailQueuesByVmta(pmta.ToMta(), deliveryServer.Select(d => d.VmtaUrl));

                        foreach (var queue in queues)
                        {
                            try
                            {
                                _mtaAgent.Pause(pmta.ToMta(), queue);

                                _logger.DebugFormat("Paused Queue {0} on {1}", queue, pmta.Host);

                                dblogEvent.EventActions.Add(new EventAction()
                                {
                                    Action = EventAction.Actions.MTAPause,
                                    ActedOnDeliveryGroupId = deliveryGroup.deliverygroup_id,
                                    Pmta = pmta,
                                    PmtaQueue = queue
                                });

                                _mtaAgent.Purge(pmta.ToMta(), queue);

                                _logger.DebugFormat("Deleted Queue {0} on {1}", queue, pmta.Host);

                                dblogEvent.EventActions.Add(new EventAction()
                                {
                                    Action = EventAction.Actions.MTAPurge,
                                    ActedOnDeliveryGroupId = deliveryGroup.deliverygroup_id,
                                    Pmta = pmta,
                                    PmtaQueue = queue
                                });
                            }
                            catch (Exception ex)
                            {
                                _logger.ErrorFormat("Pmta {0}: {1}", pmta.PmtaId, ex.UnwrapForLog(true));
                            }
                        }

                    }
                    else
                    {
                        _logger.ErrorFormat("Missing MTA credentials for {0}", deliveryServer.Key);
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorFormat("DeliveryGroup {0} DeliveryServer {1}: {2}", deliveryGroup.deliverygroup_id, deliveryServer.Key, ex.UnwrapForLog(true));
                }
            }

            _unitOfWork.SaveChanges();

            DeliveryGroup.CancelHotmailJobsByDeliveryGroup(_jobRepository, _logger, deliveryGroup, nextReset, dblogEvent);

            _unitOfWork.SaveChanges();

        }
Ejemplo n.º 17
0
        private void ResumeSecondBackOff(
            Event secondEventInstance,
            IUnitOfWork unitOfWork,
            IJobRepository jobRepository,
            IEventRepository eventRepository,
            IDeliveryGroupRepository deliveryGroupRepository,
            Event currentEvent = null
            )
        {
            var eventDetail = secondEventInstance.EventActions.FirstOrDefault(ed => ed.Action == EventAction.Actions.MTAPause);

            if (eventDetail != null && !_mtaAgent.IsQueueActive(eventDetail.Pmta.ToMta(), eventDetail.PmtaQueue))
            {
                _logger.InfoFormat("Resuming {0} on {1}", eventDetail.PmtaQueue, eventDetail.Pmta.Host);

                Event dbLogEvent = currentEvent ?? eventRepository.Add(new Event()
                                                       {
                                                           EventName = Event.EventNames.SecondBackOffResume,
                                                           Monitor = Event.Monitors.Four21,
                                                           SeriesId = secondEventInstance.SeriesId
                                                       });

                _mtaAgent.Purge(eventDetail.Pmta.ToMta(), eventDetail.PmtaQueue);
                _logger.InfoFormat("Purged {0} on {1}", eventDetail.PmtaQueue, eventDetail.Pmta.Host);

                dbLogEvent.EventActions.Add(new EventAction()
                        {
                            Action = EventAction.Actions.MTAPurge,
                            Pmta = eventDetail.Pmta,
                            PmtaQueue = eventDetail.PmtaQueue
                        });

                _mtaAgent.UnPause(eventDetail.Pmta.ToMta(), eventDetail.PmtaQueue);
                _logger.InfoFormat("Resumed {0} on {1}", eventDetail.PmtaQueue, eventDetail.Pmta.Host);

                dbLogEvent.EventActions.Add(new EventAction()
                {
                    Action = EventAction.Actions.ResumedQueue,
                    Pmta = eventDetail.Pmta,
                    PmtaQueue = eventDetail.PmtaQueue
                });

                lock (_locker)
                {
                    unitOfWork.SaveChanges();
                }
            }
        }
Ejemplo n.º 18
0
        public void ResumeMtaQueues()
        {
            var dblogEvent = new Event()
                             {
                                 EventName = Event.EventNames.ResetTime,
                                 Monitor = Event.Monitors.CancelOnBulking
                             };

            _eventRepository.Add(dblogEvent);
            _unitOfWork.SaveChanges();

            var events = Event.GetEventsToReset(_eventRepository, Event.Monitors.CancelOnBulking);
            var queues = events.SelectMany(e => e.EventActions).Where(ed => ed.Action == EventAction.Actions.MTAPause)
                            .Select(ed => new { ed.Pmta, Queue = ed.PmtaQueue }).ToArray();

            foreach (var queue in queues)
            {
                try
                {
                    if (!_mtaAgent.IsQueueActive(queue.Pmta.ToMta(), queue.Queue))
                    {
                        _mtaAgent.Purge(queue.Pmta.ToMta(), queue.Queue);
                        _logger.DebugFormat("Deleted Queue {0} on {1}", queue.Queue, queue.Pmta.Host);
                        _mtaAgent.UnPause(queue.Pmta.ToMta(), queue.Queue);
                        _logger.DebugFormat("Resumed Queue {0} on {1}", queue.Queue, queue.Pmta.Host);
                        dblogEvent.EventActions.Add(new EventAction()
                                                    {
                                                        Action = EventAction.Actions.ResumedQueue,
                                                        Pmta = queue.Pmta,
                                                        PmtaQueue = queue.Queue
                                                    });
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorFormat("Pmta {0}: {1}", queue.Pmta.PmtaId, ex.UnwrapForLog(true));
                }
            }

            _emailNotification.SendEvent(dblogEvent);

            events.ToList().ForEach(e => e.ResetEventId = dblogEvent.EventId);
            _unitOfWork.SaveChanges();
        }
Ejemplo n.º 19
0
        private DateTime GetNextResetTime(OenContext oenContext, Event.Monitors monitor, TimeSpan resetTime)
        {
            var lastReset = new DateTime();

            if (oenContext.Events.Any(ev => ev.EventName == Event.EventNames.ResetTime && ev.Monitor == monitor))
            {
                lastReset = oenContext.Events.Where(ev => ev.EventName == Event.EventNames.ResetTime && ev.Monitor == monitor).Max(ev => ev.DateCreated);
            }

            _logger.TraceFormat("Last reset {0}", lastReset);

            return lastReset.TimeOfDay > resetTime
                   ? lastReset.Subtract(lastReset.TimeOfDay).AddDays(1).Add(resetTime)
                   : lastReset.Subtract(lastReset.TimeOfDay).Add(resetTime);
        }
Ejemplo n.º 20
0
 public string GetHtml(Event dblogEvent)
 {
     switch (dblogEvent.EventName)
     {
         case Event.EventNames.SomeBulked:
             return GetContentCancelHtml(dblogEvent);
         case Event.EventNames.AllBulked:
             return GetDVGCancelHtml(dblogEvent);
         case Event.EventNames.ResetTime:
             return GetResetHtml(dblogEvent);
         case Event.EventNames.FourthBackOff:
             return GetFourthBackOffHtml(dblogEvent);
         default:
             return null;
     }
 }