Exemple #1
0
        /// <summary>
        /// Every Watchmen.ScannerContainersPeriodicity seconds lists containers from Blob storage and updates scheduler-assistant.
        /// </summary>
        /// <returns>A task object.</returns>
        public async Task Watch(CancellationToken cancellation)
        {
            var initialized = false;

            while (!cancellation.IsCancellationRequested)
            {
                try
                {
                    Logger.Information("Scanner Containers watchman is going out.");

                    try
                    {
                        var containers = await this.blobStorage.ListAllContainers();

                        var metadataTasks = containers
                                            .Select(this.DownloadAndParseMetadata)
                                            .ToArray();
                        await Task.WhenAll(metadataTasks);

                        ScannerContainer[] schedulerItems = metadataTasks
                                                            .Select(t => t.Result)
                                                            .Where(i => i != ScannerContainer.Empty)
                                                            .ToArray();
                        this.scheduler.UpdateWorkingItems(schedulerItems);

                        if (!initialized)
                        {
                            JosekiStateManager.ScannerContainersIsInitialized();
                            initialized = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex, "Scanner Containers watchman failed now, but they comes back later");
                    }

                    Logger.Information("Scanner Containers watchman finished the detour.");
                    await Task.Delay(TimeSpan.FromSeconds(this.config.Watchmen.ScannerContainersPeriodicitySeconds), cancellation);
                }
                catch (TaskCanceledException ex)
                {
                    Logger.Information(ex, "Scanner Containers watchman was canceled");
                }
            }
        }
        /// <summary>
        /// Every Watchmen.ArchiverPeriodicityHours hours:
        /// - removes expired audits from Archive,
        /// - moves processed audits to Archive.
        /// </summary>
        /// <returns>A task object.</returns>
        public async Task Watch(CancellationToken cancellation)
        {
            var initialized = false;

            while (!cancellation.IsCancellationRequested)
            {
                try
                {
                    Logger.Information("Archiver watchman is going out.");

                    try
                    {
                        // first, delete stale records, then move processed audits to archive
                        // if the order is opposite - Cleanup task has a bit more work to do
                        var deleted = await this.blobStorage.CleanupArchive(cancellation);

                        var archived = await this.blobStorage.MoveProcessedBlobsToArchive(cancellation);

                        if (!initialized)
                        {
                            JosekiStateManager.ArchiverIsInitialized();
                            initialized = true;
                        }

                        Logger.Information("Archiver archived {ArchivedCount} and deleted {DeletedCount} blobs", archived, deleted);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex, "Archiver watchman failed now, but they comes back tomorrow");
                    }

                    Logger.Information("Archiver watchman finished the detour.");
                    await Task.Delay(TimeSpan.FromHours(this.config.Watchmen.ArchiverPeriodicityHours), cancellation);
                }
                catch (TaskCanceledException ex)
                {
                    Logger.Information(ex, "Archiver watchman was canceled");
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Every Watchmen.InfraScorePeriodicityHours hours forces cache reload.
        /// </summary>
        /// <returns>A task object.</returns>
        public async Task Watch(CancellationToken cancellation)
        {
            var initialized = false;

            while (!cancellation.IsCancellationRequested)
            {
                try
                {
                    Logger.Information("InfraScoreCache watchman is going out.");

                    using var scope = this.services.CreateScope();
                    var cache  = scope.ServiceProvider.GetRequiredService <IInfrastructureScoreCache>();
                    var config = scope.ServiceProvider.GetRequiredService <ConfigurationParser>().Get();

                    try
                    {
                        await cache.ReloadEntireCache();

                        if (!initialized)
                        {
                            JosekiStateManager.ScoreCacheIsInitialized();
                            initialized = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex, "InfraScoreCache watchman failed now, but they comes back later");
                    }

                    Logger.Information("InfraScoreCache watchman finished the detour.");
                    await Task.Delay(TimeSpan.FromHours(config.Watchmen.InfraScorePeriodicityHours), cancellation);
                }
                catch (TaskCanceledException ex)
                {
                    Logger.Information(ex, "InfraScoreCache watchman was canceled");
                }
            }
        }