protected override async Task <JobResult> RunInternalAsync(JobContext context)
        {
            _logger.LogTrace("Start save stack event counts.");
            await _stackService.SaveStackUsagesAsync(cancellationToken : context.CancellationToken).AnyContext();

            _logger.LogTrace("Finished save stack event counts.");
            return(JobResult.Success);
        }
        private async Task CreateEventsAsync(int eventCount, string[] projectIds, decimal?value = -1)
        {
            var events = EventData.GenerateEvents(eventCount, projectIds: projectIds, startDate: SystemClock.OffsetUtcNow.SubtractDays(3), endDate: SystemClock.OffsetUtcNow, value: value);

            foreach (var eventGroup in events.GroupBy(ev => ev.ProjectId))
            {
                await _pipeline.RunAsync(eventGroup, OrganizationData.GenerateSampleOrganization(_billingManager, _plans), ProjectData.GenerateSampleProject());
            }
            await _stackService.SaveStackUsagesAsync();

            await _configuration.Client.RefreshAsync(Indices.All);
        }
Example #3
0
        public async Task CanSaveStackUsage()
        {
            var stack = await _stackRepository.AddAsync(StackData.GenerateStack(id: TestConstants.StackId, projectId: TestConstants.ProjectId, organizationId: TestConstants.OrganizationId));

            var      utcNow = SystemClock.UtcNow.Floor(TimeSpan.FromMilliseconds(1));
            DateTime minOccurrenceDate = utcNow.AddMinutes(-1), maxOccurrenceDate = utcNow;
            await _stackService.IncrementStackUsageAsync(TestConstants.OrganizationId, TestConstants.ProjectId, stack.Id, minOccurrenceDate, maxOccurrenceDate, 10);

            await _stackService.SaveStackUsagesAsync(false);

            // Assert state in cache after save stack usage
            Assert.Equal(0, await _cache.GetAsync <long>(_stackService.GetStackOccurrenceCountCacheKey(stack.Id), 0));

            // Assert stack state after save stack usage
            stack = await _stackRepository.GetByIdAsync(TestConstants.StackId);

            Assert.Equal(10, stack.TotalOccurrences);
            Assert.Equal(minOccurrenceDate, stack.FirstOccurrence);
            Assert.Equal(maxOccurrenceDate, stack.LastOccurrence);
        }