예제 #1
0
        public override void ProcessBatch(ICollection <EventContext> contexts)
        {
            var stacks = contexts.Where(c => !c.IsNew).GroupBy(c => c.Event.StackId);

            foreach (var stackGroup in stacks)
            {
                int      count   = stackGroup.Count();
                DateTime minDate = stackGroup.Min(s => s.Event.Date.UtcDateTime);
                DateTime maxDate = stackGroup.Max(s => s.Event.Date.UtcDateTime);
                _stackRepository.IncrementEventCounter(stackGroup.First().Event.OrganizationId, stackGroup.Key, minDate, maxDate, count);

                // update stacks in memory since they are used in notifications
                foreach (var ctx in stackGroup)
                {
                    if (ctx.Stack.FirstOccurrence > minDate)
                    {
                        ctx.Stack.FirstOccurrence = minDate;
                    }
                    if (ctx.Stack.LastOccurrence < maxDate)
                    {
                        ctx.Stack.LastOccurrence = maxDate;
                    }
                    ctx.Stack.TotalOccurrences += count;
                }
            }
        }
        public void IncrementEventCounterTest()
        {
            RemoveData();
            _repository.Add(StackData.GenerateStack(id: TestConstants.StackId, projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId));
            _client.Refresh();

            var stack = _repository.GetById(TestConstants.StackId);

            Assert.NotNull(stack);
            Assert.Equal(0, stack.TotalOccurrences);
            Assert.Equal(DateTime.MinValue, stack.FirstOccurrence);
            Assert.Equal(DateTime.MinValue, stack.LastOccurrence);

            var utcNow = DateTime.UtcNow;

            _repository.IncrementEventCounter(TestConstants.OrganizationId, TestConstants.StackId, utcNow);
            _client.Refresh();

            stack = _repository.GetById(TestConstants.StackId);
            Assert.Equal(1, stack.TotalOccurrences);
            Assert.Equal(utcNow, stack.FirstOccurrence);
            Assert.Equal(utcNow, stack.LastOccurrence);

            _repository.IncrementEventCounter(TestConstants.OrganizationId, TestConstants.StackId, utcNow.SubtractDays(1));
            _client.Refresh();

            stack = _repository.GetById(TestConstants.StackId);
            Assert.Equal(2, stack.TotalOccurrences);
            Assert.Equal(utcNow.SubtractDays(1), stack.FirstOccurrence);
            Assert.Equal(utcNow, stack.LastOccurrence);

            _repository.IncrementEventCounter(TestConstants.OrganizationId, TestConstants.StackId, utcNow.AddDays(1));
            _client.Refresh();

            stack = _repository.GetById(TestConstants.StackId);
            Assert.Equal(3, stack.TotalOccurrences);
            Assert.Equal(utcNow.SubtractDays(1), stack.FirstOccurrence);
            Assert.Equal(utcNow.AddDays(1), stack.LastOccurrence);
        }
        public override void Process(EventContext ctx)
        {
            // TODO: Implement batch incrementing to reduce pipeline cost.
            //_organizationCounters.AddOrUpdate(ctx.Event.OrganizationId, 1, (key, value) => value + 1);
            //_projectCounters.AddOrUpdate(ctx.Event.ProjectId, 1, (key, value) => value + 1);

            _organizationRepository.IncrementEventCounter(ctx.Event.OrganizationId);
            _projectRepository.IncrementEventCounter(ctx.Event.ProjectId);
            if (!ctx.IsNew)
            {
                _stackRepository.IncrementEventCounter(ctx.Event.OrganizationId, ctx.Event.StackId, ctx.Event.Date.UtcDateTime);
            }
        }
예제 #4
0
        public override void ProcessBatch(ICollection <EventContext> contexts)
        {
            var stacks = contexts.Where(c => !c.IsNew).GroupBy(c => c.Event.StackId);

            foreach (var stackGroup in stacks)
            {
                try {
                    int      count   = stackGroup.Count();
                    DateTime minDate = stackGroup.Min(s => s.Event.Date.UtcDateTime);
                    DateTime maxDate = stackGroup.Max(s => s.Event.Date.UtcDateTime);
                    _stackRepository.IncrementEventCounter(stackGroup.First().Event.OrganizationId, stackGroup.First().Event.ProjectId, stackGroup.Key, minDate, maxDate, count);

                    // Update stacks in memory since they are used in notifications.
                    foreach (var ctx in stackGroup)
                    {
                        if (ctx.Stack.FirstOccurrence > minDate)
                        {
                            ctx.Stack.FirstOccurrence = minDate;
                        }

                        if (ctx.Stack.LastOccurrence < maxDate)
                        {
                            ctx.Stack.LastOccurrence = maxDate;
                        }

                        ctx.Stack.TotalOccurrences += count;
                    }
                } catch (Exception ex) {
                    foreach (var context in stackGroup)
                    {
                        bool cont = false;
                        try {
                            cont = HandleError(ex, context);
                        } catch {}

                        if (!cont)
                        {
                            context.SetError(ex.Message, ex);
                        }
                    }
                }
            }
        }