Exemple #1
0
        private async Task EnforceEventCountLimitsAsync(Organization organization, JobContext context)
        {
            int retentionDays = organization.RetentionDays;

            if (_appOptions.MaximumRetentionDays > 0 && retentionDays > _appOptions.MaximumRetentionDays)
            {
                retentionDays = _appOptions.MaximumRetentionDays;
            }

            if (retentionDays < 1)
            {
                return;
            }

            var nextPlan = _billingManager.GetBillingPlanByUpsellingRetentionPeriod(organization.RetentionDays);

            if (nextPlan != null)
            {
                retentionDays = nextPlan.RetentionDays;
            }

            var cutoff = SystemClock.UtcNow.Date.SubtractDays(retentionDays);

            _logger.LogInformation("Enforcing event count limits older than {RetentionPeriod:g} for organization {OrganizationName} ({OrganizationId}).", cutoff, organization.Name, organization.Id);

            await RenewLockAsync(context).AnyContext();

            long removedEvents = await _eventRepository.RemoveAllAsync(organization.Id, null, null, cutoff).AnyContext();

            _logger.LogInformation("Enforced retention period for {OrganizationName} ({OrganizationId}), Removed {RemovedEvents} Events", organization.Name, organization.Id, removedEvents);
        }
Exemple #2
0
        private async Task EnforceEventRetentionDaysAsync(Organization organization, JobContext context)
        {
            int retentionDays = organization.RetentionDays;

            if (_appOptions.MaximumRetentionDays > 0 && retentionDays > _appOptions.MaximumRetentionDays)
            {
                retentionDays = _appOptions.MaximumRetentionDays;
            }

            if (retentionDays < 1)
            {
                return;
            }

            var nextPlan = _billingManager.GetBillingPlanByUpsellingRetentionPeriod(organization.RetentionDays);

            if (nextPlan != null)
            {
                retentionDays = nextPlan.RetentionDays;
            }

            var cutoff = SystemClock.UtcNow.Date.SubtractDays(retentionDays);

            _logger.RetentionEnforcementStart(cutoff, organization.Name, organization.Id);

            await RenewLockAsync(context).AnyContext();

            long removedEvents = await _eventRepository.RemoveAllAsync(organization.Id, null, null, cutoff).AnyContext();

            _logger.RetentionEnforcementComplete(organization.Name, organization.Id, removedEvents);
        }
        private async Task EnforceEventCountLimitsAsync(Organization organization)
        {
            Logger.Info().Message("Enforcing event count limits for organization '{0}' with Id: '{1}'", organization.Name, organization.Id).Write();

            try {
                int retentionDays = organization.RetentionDays;

                var nextPlan = BillingManager.GetBillingPlanByUpsellingRetentionPeriod(organization.RetentionDays);
                if (nextPlan != null)
                {
                    retentionDays = nextPlan.RetentionDays;
                }

                DateTime cutoff = DateTime.UtcNow.Date.SubtractDays(retentionDays);
                await _eventRepository.RemoveAllByDateAsync(organization.Id, cutoff).AnyContext();
            } catch (Exception ex) {
                Logger.Error().Message("Error enforcing limits: org={0} id={1} message=\"{2}\"", organization.Name, organization.Id, ex.Message).Exception(ex).Write();
            }
        }
Exemple #4
0
        public void GetBillingPlanByUpsellingRetentionPeriod()
        {
            var plan = BillingManager.GetBillingPlanByUpsellingRetentionPeriod(BillingManager.FreePlan.RetentionDays);

            Assert.NotNull(plan);
            Assert.Equal(BillingManager.SmallPlan.Id, plan.Id);
            Assert.Equal(BillingManager.SmallPlan.RetentionDays, plan.RetentionDays);

            plan = BillingManager.GetBillingPlanByUpsellingRetentionPeriod(BillingManager.SmallPlan.RetentionDays);
            Assert.NotNull(plan);
            Assert.Equal(BillingManager.MediumPlan.Id, plan.Id);
            Assert.Equal(BillingManager.MediumPlan.RetentionDays, plan.RetentionDays);

            plan = BillingManager.GetBillingPlanByUpsellingRetentionPeriod(BillingManager.MediumPlan.RetentionDays);
            Assert.NotNull(plan);
            Assert.Equal(BillingManager.LargePlan.Id, plan.Id);
            Assert.Equal(BillingManager.LargePlan.RetentionDays, plan.RetentionDays);

            plan = BillingManager.GetBillingPlanByUpsellingRetentionPeriod(BillingManager.LargePlan.RetentionDays);
            Assert.Null(plan);
        }
    private async Task EnforceRetentionAsync(JobContext context)
    {
        var results = await _organizationRepository.FindAsync(q => q.Include(o => o.Id, o => o.Name, o => o.RetentionDays), o => o.SearchAfterPaging().PageLimit(100)).AnyContext();

        while (results.Documents.Count > 0 && !context.CancellationToken.IsCancellationRequested)
        {
            foreach (var organization in results.Documents)
            {
                using var _ = _logger.BeginScope(new ExceptionlessState().Organization(organization.Id));

                int retentionDays = _billingManager.GetBillingPlanByUpsellingRetentionPeriod(organization.RetentionDays)?.RetentionDays ?? _appOptions.MaximumRetentionDays;
                if (retentionDays <= 0)
                {
                    retentionDays = _appOptions.MaximumRetentionDays;
                }
                retentionDays = Math.Min(retentionDays, _appOptions.MaximumRetentionDays);

                try {
                    // adding 60 days to retention in order to keep track of whether a stack is new or not
                    await EnforceStackRetentionDaysAsync(organization, retentionDays + 60, context).AnyContext();
                    await EnforceEventRetentionDaysAsync(organization, retentionDays, context).AnyContext();
                }
                catch (Exception ex) {
                    _logger.LogError(ex, "Error enforcing retention for Organization {OrganizationId}: {Message}", organization.Id, ex.Message);
                }

                // Sleep so we are not hammering the backend.
                await SystemClock.SleepAsync(TimeSpan.FromSeconds(2.5)).AnyContext();
            }

            if (context.CancellationToken.IsCancellationRequested || !await results.NextPageAsync().AnyContext())
            {
                break;
            }
        }
    }
        private async Task EnforceEventCountLimitsAsync(Organization organization)
        {
            _logger.Info("Enforcing event count limits for organization '{0}' with Id: '{1}'", organization.Name, organization.Id);

            try {
                int retentionDays = organization.RetentionDays;

                var nextPlan = BillingManager.GetBillingPlanByUpsellingRetentionPeriod(organization.RetentionDays);
                if (nextPlan != null)
                {
                    retentionDays = nextPlan.RetentionDays;
                }

                if (Settings.Current.MaximumRetentionDays > 0 && retentionDays > Settings.Current.MaximumRetentionDays)
                {
                    retentionDays = Settings.Current.MaximumRetentionDays;
                }

                var cutoff = SystemClock.UtcNow.Date.SubtractDays(retentionDays);
                await _eventRepository.RemoveAllByDateAsync(organization.Id, cutoff).AnyContext();
            } catch (Exception ex) {
                _logger.Error(ex, "Error enforcing limits: org={0} id={1} message=\"{2}\"", organization.Name, organization.Id, ex.Message);
            }
        }