Exemplo n.º 1
0
    /// <inheritdoc />
    public override Task PerformExecuteAsync(object?state)
    {
        // Globally disabled by feature flag
        if (!_settingsMonitor.CurrentValue.ContentVersionCleanupPolicy.EnableCleanup)
        {
            _logger.LogInformation(
                "ContentVersionCleanup task will not run as it has been globally disabled via configuration");
            return(Task.CompletedTask);
        }

        if (_runtimeState.Level != RuntimeLevel.Run)
        {
            return(Task.FromResult(true)); // repeat...
        }

        // Don't run on replicas nor unknown role servers
        switch (_serverRoleAccessor.CurrentServerRole)
        {
        case ServerRole.Subscriber:
            _logger.LogDebug("Does not run on subscriber servers");
            return(Task.CompletedTask);

        case ServerRole.Unknown:
            _logger.LogDebug("Does not run on servers with unknown role");
            return(Task.CompletedTask);

        case ServerRole.Single:
        case ServerRole.SchedulingPublisher:
        default:
            break;
        }

        // Ensure we do not run if not main domain, but do NOT lock it
        if (!_mainDom.IsMainDom)
        {
            _logger.LogDebug("Does not run if not MainDom");
            return(Task.FromResult(false)); // do NOT repeat, going down
        }

        var count = _service.PerformContentVersionCleanup(DateTime.Now).Count;

        if (count > 0)
        {
            _logger.LogInformation("Deleted {count} ContentVersion(s)", count);
        }
        else
        {
            _logger.LogDebug("Task complete, no items were Deleted");
        }

        return(Task.FromResult(true));
    }
Exemplo n.º 2
0
        public override bool PerformRun()
        {
            // Globally disabled by feature flag
            if (!_settings.EnableCleanup)
            {
                _logger.Info <ContentVersionCleanup>("ContentVersionCleanup task will not run as it has been globally disabled via configuration.");
                return(false);
            }

            if (_runtimeState.Level != RuntimeLevel.Run)
            {
                return(true); // repeat...
            }

            switch (_runtimeState.ServerRole)
            {
            case ServerRole.Replica:
                _logger.Debug <ContentVersionCleanup>("Does not run on replica servers.");
                return(true);    // DO repeat, server role can change

            case ServerRole.Unknown:
                _logger.Debug <ContentVersionCleanup>("Does not run on servers with unknown role.");
                return(true);    // DO repeat, server role can change

            case ServerRole.Single:
            case ServerRole.Master:
            default:
                break;
            }

            // Ensure we do not run if not main domain, but do NOT lock it
            if (!_runtimeState.IsMainDom)
            {
                _logger.Debug <ContentVersionCleanup>("Does not run if not MainDom.");
                return(false); // do NOT repeat, going down
            }

            var count = _service.PerformContentVersionCleanup(DateTime.Now).Count;

            if (count > 0)
            {
                _logger.Info <ContentVersionCleanup>("Deleted {count} ContentVersion(s).", count);
            }
            else
            {
                _logger.Debug <ContentVersionCleanup>("Task complete, no items were Deleted.");
            }

            return(true);
        }