Пример #1
0
 public static IQueryable<Pmta> GetPmtasByDeliveryGroup(IPmtaRepository pmtaRepository, DeliveryGroup deliveryGroup)
 {
     return (from dsi in pmtaRepository.GetDeliveryServerIps()
             where dsi.deliveryserver_id.HasValue && dsi.deliverygroup_id.HasValue && dsi.deliverygroup_id == deliveryGroup.deliverygroup_id
             join pmta in pmtaRepository.GetAll() on dsi.deliveryserver_id equals pmta.deliveryserver_id
             select pmta).Distinct();
 }
Пример #2
0
        public static IQueryable<IGrouping<int, DeliveryServerIp>> GetVmtasGroupedByDeliveryServerForDeliveryGroup(IPmtaRepository pmtaRepository, DeliveryGroup deliveryGroup)
        {

            return from dsi in pmtaRepository.GetDeliveryServerIps()
                   where dsi.deliveryserver_id.HasValue && dsi.deliverygroup_id.HasValue && dsi.deliverygroup_id == deliveryGroup.deliverygroup_id && dsi.enabled && dsi.DeliveryServer.enabled
                   group dsi by dsi.deliveryserver_id.Value into g
                   select g;
        }
Пример #3
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());
        }
Пример #4
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();

        }
Пример #5
0
        public void Reset()
        {
            var eventsGenerated = new List<Event>();
            var emailSent = false;

            #region setup

            EventRepo.Setup(m => m.GetAll()).Returns(() => new List<Event>()
                                                           {
                                                               new Event()
                                                               {
                                                                   EventId = 1,
                                                                   EventName = Event.EventNames.SecondBackOff,
                                                                   DateCreated = DateTime.Now.AddMinutes(-1),
                                                                   Monitor = Event.Monitors.Four21,
                                                                   EventActions = new EventAction[]
                                                                                  {
                                                                                      new EventAction()
                                                                                      {
                                                                                          Action = EventAction.Actions.MTAPause,
                                                                                          PmtaId = Pmtas.First().PmtaId,
                                                                                          Pmta = Pmtas.First(),
                                                                                          PmtaQueue = "domain/vmta",
                                                                                          EventId = 1
                                                                                      }
                                                                                  }
                                                               },
                                                               new Event()
                                                               {
                                                                   EventId = 2,
                                                                   EventName = Event.EventNames.FourthBackOff,
                                                                   DateCreated = DateTime.Now.AddMinutes(-1),
                                                                   Monitor = Event.Monitors.Four21,
                                                                   EventActions = new EventAction[]
                                                                                  {
                                                                                      new EventAction()
                                                                                      {
                                                                                          Action = EventAction.Actions.MTAPause,
                                                                                          PmtaId = Pmtas.First().PmtaId,
                                                                                          Pmta = Pmtas.First(),
                                                                                          PmtaQueue = "domain2/vmta",
                                                                                          EventId = 2
                                                                                      }
                                                                                  }
                                                               }
                                                           }.AsQueryable());

            EventRepo.Setup(m => m.Add(It.IsAny<Event>()))
                     .Returns<Event>(e =>
                     {
                         eventsGenerated.Add(e);
                         return e;
                     });

            DeliveryGroupRepo.Setup(m => m.GetDeliveryServerIps()).Returns(() => new List<DeliveryServerIp>()
                                                                                 {
                                                                                     new DeliveryServerIp()
                                                                                     {
                                                                                         deliveryserver_id = 1,
                                                                                         VmtaUrl = "vmta",
                                                                                         deliveryserverip_id = 1,
                                                                                         deliverygroup_id = 1
                                                                                     }
                                                                                 }.AsQueryable());

            var deliveryGroup = new DeliveryGroup()
            {
                deliverygroup_id = 1,
                CancelOnBulkingEnabled = true
            };

            DeliveryGroupRepo.Setup(m => m.GetAll()).Returns(() => new List<DeliveryGroup>()
                                                               {
                                                                   deliveryGroup
                                                               }.AsQueryable());

            JobRepo.Setup(m => m.GetAll()).Returns(() => new List<Job>()
                                                     {
                                                         new Job()
                                                         {
                                                             job_id = 1,
                                                             deliverygroup_id = deliveryGroup.deliverygroup_id,
                                                             DeliveryGroup = deliveryGroup,
                                                             datelaunch = DateTime.Now,
                                                             jobstatus_id = 1
                                                         },
                                                         new Job()
                                                         {
                                                             job_id = 1,
                                                             deliverygroup_id = deliveryGroup.deliverygroup_id,
                                                             DeliveryGroup = deliveryGroup,
                                                             datelaunch = DateTime.Now.AddDays(1),
                                                             jobstatus_id = 1
                                                         }
                                                     }.AsQueryable());

            Mta.Setup(m => m.IsQueueActive(It.IsAny<Mta>(), It.IsAny<string>())).Returns(() => false);

            Notification.Setup(m => m.SendEvent(It.IsAny<Event>())).Callback(() => emailSent = true);

            #endregion

            var nextReset = DateTime.Today.AddDays(1);

            F21.ResumeQueues(nextReset);

            var events = eventsGenerated.Where(e => e.EventName == Event.EventNames.ResetTime);

            if (events.Count() != 1)
            {
                Assert.Fail("No Event");
            }
            else
            {
                var actions = events.First().EventActions;

                Assert.IsTrue(actions.Count(a => a.Action == EventAction.Actions.ResumedQueue) == 2
                              && actions.Count(a => a.Action == EventAction.Actions.MTAPurge) == 2
                              && actions.Count(a => a.Action == EventAction.Actions.JobCancel) == 1
                              && emailSent);
            }

        }