コード例 #1
0
ファイル: JobQueue.cs プロジェクト: vilvm88/dos
        private async Task RemoveOldJobsProcess(CancellationToken token)
        {
            while (true)
            {
                try
                {
                    await Task.Delay(_options.CleaningInMemoryStoragePeriod, token).ConfigureAwait(false);

                    lock (_locker)
                    {
                        var jobs = _jobs.Where(x => x.IsArchived && DateTime.Now - x.Job.CreationTimestamp > _options.MaximumInMemoryStorageTime).ToArray();

                        foreach (var job in jobs)
                        {
                            _jobs.Remove(job);
                        }

                        _logger?.Debug($"Removed {jobs.Length} jobs from queue {Name}.");
                    }
                }
                catch (OperationCanceledException)
                {
                    break;
                }
                catch (Exception exception)
                {
                    _logger?.Error(exception);
                }
            }
        }