public void setup()
        {
            _pollerSource = Substitute.For<IPollSource<string>>();
            _pollerSource.TryGet(out dummy).Returns(false);

            _subject = new PollingWorkQueue<string>(_pollerSource);
        }
 public void setup()
 {
     _dispatcher = Substitute.For<IDispatch<object>>();
     _queue = new InMemoryWorkQueue<object>();
     _subject = new DirectWorkerPool<object>();
     _subject.SetSource(_dispatcher, _queue);
 }
 public override void setup()
 {
     _output = new List<string>();
     _boundedWorkQueue = new BoundedWorkQueue<string>(Bound);
     _subject = new Dispatch<string>(
         _boundedWorkQueue,
         new DirectWorkerPool<string>());
 }
 public void setup()
 {
     _actionCalled = false;
     _dispatcher = Substitute.For<IDispatch<object>>();
     _dispatcher.MaximumInflight().Returns(1);
     _queue = Substitute.For<IWorkQueue<object>>();
     _subject = new ThreadedWorkerPool<object>("name", 1);
     _subject.SetSource(_dispatcher, _queue);
 }
 public override void setup()
 {
     _output = new List<string>();
     _boundedWorkQueue = new BoundedWorkQueue<string>(Bound);
     _subject = new Dispatch<string>(
         _boundedWorkQueue,
         new ThreadedWorkerPool<string>("Test", 8));
     _maxQueueSize = 0;
 }
Example #6
0
            public void Add(IWorkQueue queue, bool autoUpdate)
            {
                if (!ListsByPriority.TryGetValue(queue.Priority, out ListForPriority lfp))
                {
                    ListsByPriority[queue.Priority] = lfp = new ListForPriority(queue.Priority);
                }
                lfp.Add(queue);

                if (autoUpdate)
                {
                    UpdateItems();
                }
            }
    public IngressController(
        ICache cache,
        IReconciler reconciler,
        IResourceInformer <V1Ingress> ingressInformer,
        IResourceInformer <V1Service> serviceInformer,
        IResourceInformer <V1Endpoints> endpointsInformer,
        IHostApplicationLifetime hostApplicationLifetime,
        ILogger <IngressController> logger)
        : base(hostApplicationLifetime, logger)
    {
        if (ingressInformer is null)
        {
            throw new ArgumentNullException(nameof(ingressInformer));
        }

        if (serviceInformer is null)
        {
            throw new ArgumentNullException(nameof(serviceInformer));
        }

        if (endpointsInformer is null)
        {
            throw new ArgumentNullException(nameof(endpointsInformer));
        }

        if (hostApplicationLifetime is null)
        {
            throw new ArgumentNullException(nameof(hostApplicationLifetime));
        }

        if (logger is null)
        {
            throw new ArgumentNullException(nameof(logger));
        }

        _registrations = new[]
        {
            ingressInformer.Register(Notification),
            serviceInformer.Register(Notification),
            endpointsInformer.Register(Notification),
        };

        _queue = new ProcessingRateLimitedQueue <QueueItem>(perSecond: 0.5, burst: 1);

        _cache      = cache ?? throw new ArgumentNullException(nameof(cache));
        _reconciler = reconciler ?? throw new ArgumentNullException(nameof(reconciler));
        _reconciler.OnAttach(TargetAttached);

        _ingressChangeQueueItem = new QueueItem("Ingress Change", null);
    }
Example #8
0
        public Consumer(IWorkQueue workQueue, ITransformer transformer)
        {
            if (workQueue == null)
            {
                throw new ArgumentNullException(nameof(workQueue));
            }
            if (transformer == null)
            {
                throw new ArgumentNullException(nameof(transformer));
            }

            _workQueue   = workQueue;
            _transformer = transformer;
        }
        public static Task EnqueueAsync([NotNull] this IWorkQueue workQueue, [NotNull] object item, [CanBeNull] DateTime?whenToProcess = null)
        {
            if (workQueue is null)
            {
                throw new ArgumentNullException(nameof(workQueue));
            }

            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            return(workQueue.EnqueueManyAsync(new[] { item }, whenToProcess));
        }
Example #10
0
        /// <summary> Batch process works </summary>
        /// <param name="queue"> Work Queue instance </param>
        /// <param name="works"> Works to process </param>
        /// <param name="cancellation"> Processing cancellation token </param>
        /// <param name="attemptsCount"> Retry on fail attempts count </param>
        /// <param name="enqueueAll"> Option to enqueue all data first </param>
        /// <typeparam name="TResult"> Processing result type </typeparam>
        /// <returns> Processing result task enumeration </returns>
        /// <exception cref="ArgumentNullException"> Thrown if <paramref name="queue" /> or <paramref name="works" /> is NULL </exception>
        public static async IAsyncEnumerable <TResult> DoWorkAsync <TResult>(this IWorkQueue queue, IEnumerable <IWork <TResult> > works,
                                                                             [EnumeratorCancellation] CancellationToken cancellation = default, int attemptsCount = 1, bool enqueueAll = false)
        {
            _ = queue ?? throw new ArgumentNullException(nameof(queue));
            var results = (works ?? throw new ArgumentNullException(nameof(works))).Select(work => queue.EnqueueWork(work, cancellation, attemptsCount));

            if (enqueueAll)
            {
                results = results.ToList();
            }
            foreach (var result in results)
            {
                yield return(await result.ConfigureAwait(false));
            }
        }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="context"></param>
 /// <param name="logger"></param>
 /// <param name="mapper"></param>
 /// <param name="httpClient"></param>
 /// <param name="appSettings"></param>
 /// <param name="analyticsService"></param>
 /// <param name="recommendationService"></param>
 /// <param name="distributedCache"></param>
 /// <param name="workQueue"></param>
 /// <param name="popularityService"></param>
 public EventService(ApplicationContext context, ILogger <EventService> logger, IMapper mapper,
                     HttpClient httpClient, IOptions <AppSettings> appSettings, IAnalyticsService analyticsService,
                     IRecommendationService recommendationService, IDistributedCache distributedCache,
                     IWorkQueue workQueue, IPopularityService popularityService)
 {
     Logger                = logger;
     ApplicationContext    = context;
     Mapper                = mapper;
     HttpClient            = httpClient;
     AppSettings           = appSettings.Value;
     AnalyticsService      = analyticsService;
     RecommendationService = recommendationService;
     DistributedCache      = distributedCache;
     WorkQueue             = workQueue;
     PopularityService     = popularityService;
 }
        public void enqueue_is_exception_safe()
        {
            _subject = new BoundedWorkQueue<object>(_mockQueue, 1);

            var objectToThrowAt = new object();
            _mockQueue.When(queue => queue.Enqueue(objectToThrowAt))
                      .Do(_ => { throw new DummyException(); });

            try
            {
                _subject.Enqueue(objectToThrowAt);
            }
            catch (DummyException)
            {
            }

            _subject.Enqueue(new object());
        }
Example #13
0
        public Producer(IWorkQueue workQueue, IEnumerable <IXPathNavigable> documents, string outputDir)
        {
            if (workQueue == null)
            {
                throw new ArgumentNullException(nameof(workQueue));
            }
            if (documents == null)
            {
                throw new ArgumentNullException(nameof(documents));
            }
            if (outputDir == null)
            {
                throw new ArgumentNullException(nameof(outputDir));
            }

            _workQueue = workQueue;
            _documents = documents;
            _outputDir = outputDir;
        }
Example #14
0
        /// <inheritdoc cref="DoWorkAsync{TResult}(IWorkQueue,IEnumerable{IAsyncWork{TResult}},CancellationToken,int,bool)" />
        public static async IAsyncEnumerable <TResult> DoWorkAsync <TResult>(this IWorkQueue queue, IAsyncEnumerable <IAsyncWork <TResult> > works,
                                                                             [EnumeratorCancellation] CancellationToken cancellation = default, int attemptsCount = 1)
        {
            _ = queue ?? throw new ArgumentNullException(nameof(queue));
            var channel = Channel.CreateUnbounded <Task <TResult> >(new UnboundedChannelOptions {
                SingleReader = true, SingleWriter = true
            });
            var reader = channel.Reader;
            var writer = channel.Writer;

            _ = Task.Run(async() =>
            {
                try
                {
                    await foreach (var work in works.WithCancellation(cancellation).ConfigureAwait(false))
                    {
                        await writer.WriteAsync(queue.EnqueueAsyncWork(work, cancellation, attemptsCount), cancellation).ConfigureAwait(false);
                    }
                }
                catch (OperationCanceledException ex)
                {
                    await writer.WriteAsync(Task.FromCanceled <TResult>(ex.CancellationToken), CancellationToken.None).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    await writer.WriteAsync(Task.FromException <TResult>(ex), cancellation).ConfigureAwait(false);
                }
                finally
                {
                    writer.Complete();
                }
            },
                         cancellation);
            while (await reader.WaitToReadAsync(cancellation).ConfigureAwait(false))
            {
                yield return(await(await reader.ReadAsync(cancellation).ConfigureAwait(false)).ConfigureAwait(false));
            }
        }
Example #15
0
 public void Unregister(IWorkQueue wq)
 {
     lock (m_queues) m_queues.Remove(wq);
 }
 public CommandHandler(IWorkQueue workQueue, IServiceProvider serviceProvider)
 {
     _workQueue       = workQueue;
     _serviceProvider = serviceProvider;
 }
Example #17
0
 public void setup()
 {
     _queue = Substitute.For<IWorkQueue<object>>();
     _pool = Substitute.For<IWorkerPool<object>>();
     _pool.PoolSize().Returns(10000);
     _subject = new Dispatch<object>(_queue, _pool);
 }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WorkQueueBase{TItem}" /> class.
 /// </summary>
 /// <param name="workQueue">The work queue.</param>
 public WorkQueueBase(IWorkQueue <TItem> workQueue) => _base = workQueue;
Example #19
0
 public WorkQueueException(IWorkQueue queue, string message)
     : base(message)
 {
     Queue = queue;
 }
Example #20
0
 /// <summary> Enqueue background work </summary>
 /// <param name="queue"> Work queue instance </param>
 /// <param name="cancellation"> Work cancellation token </param>
 /// <param name="attemptsCount"> Retry on fail attempts count </param>
 /// <typeparam name="TWork"> Work type </typeparam>
 /// <returns> Work completion task </returns>
 /// <exception cref="ArgumentNullException"> Thrown if <paramref name="queue" /> is NULL </exception>
 public static Task EnqueueWork <TWork>(this IWorkQueue queue, CancellationToken cancellation = default, int attemptsCount = 1)
     where TWork : IWork
 => (queue ?? throw new ArgumentNullException(nameof(queue))).EnqueueWork(
 /// <inheritdoc />
 public BackGroundWorkService(ILogger <BackGroundWorkService> logger, IWorkQueue workQueue)
 {
     Logger    = logger;
     WorkQueue = workQueue;
 }
Example #22
0
 public RepositoryController(ILoggerFactory logFactory, IAuthHandler auth, IClientFactory clientFactory, IIndexStore indexStore, IWorkQueue <IndexRequest> indexQueue, ISecurityScanner secScanner = null) :
     base(logFactory, auth)
 {
     this.clientFactory = clientFactory;
     this.logger        = logFactory.CreateLogger <RepositoryController>();
     this.indexStore    = indexStore;
     this.indexQueue    = indexQueue;
     this.secScanner    = secScanner;
 }
Example #23
0
 public ClairScanner(ILogger <ClairScanner> logger, ServiceConfig config, IClairAPI clair, ICacheFactory cacheFactory, IWorkQueue <ScanRequest> queue)
 {
     this.logger       = logger;
     this.config       = config;
     this.clair        = clair;
     this.cacheFactory = cacheFactory;
     Queue             = queue;
 }
Example #24
0
 public WorkQueueBatch(IWorkQueue queue)
 {
     mQueue = queue;
 }
Example #25
0
 /// <inheritdoc cref="DoWorkAsync{TResult}(IWorkQueue,IEnumerable{IWork{TResult}},CancellationToken,int,bool)" />
 public static IAsyncEnumerable <TResult> DoWorkAsync <TResult>(this IEnumerable <IWork <TResult> > works, IWorkQueue queue,
                                                                CancellationToken cancellation = default, int attemptsCount = 1, bool enqueueAll = false)
 => (queue ?? throw new ArgumentNullException(nameof(queue))).DoWorkAsync(works, cancellation, attemptsCount, enqueueAll);
Example #26
0
        /// <summary> Enqueue asynchronous access action into work queue with given <paramref name="priority" /> (if supported) </summary>
        /// <param name="queue"> Work queue instance </param>
        /// <param name="priority"> Access action priority </param>
        /// <param name="cancellation"> Access cancellation token </param>
        /// <param name="attemptsCount"> Retry on fail attempts count </param>
        /// <typeparam name="TResource"> Shared resource type</typeparam>
        /// <typeparam name="TAsyncAccess"> Access action type </typeparam>
        /// <typeparam name="TResult"> Access action result type </typeparam>
        /// <returns> Access action completion task </returns>
        /// <exception cref="ArgumentNullException"> Thrown if <paramref name="queue" /> is NULL </exception>
        public static Task <TResult> EnqueueAsyncAccess <TResource, TAsyncAccess, TResult>(this IWorkQueue queue, CancellationToken cancellation = default,
                                                                                           int attemptsCount = 1, int priority = 0)
            where TResource : notnull
            where TAsyncAccess : IAsyncAccess <TResource, TResult>
        {
            var work = CreateAsyncWork((provider, cancel)
                                       => provider.EnqueueAsyncAccess <TResource, TAsyncAccess, TResult>(cancel, attemptsCount, priority));

            return((queue ?? throw new ArgumentNullException(nameof(queue))) is IPriorityWorkQueue priorityQueue
            ? priorityQueue.EnqueueAsyncWork(work, priority, cancellation)
            : queue.EnqueueAsyncWork(work, cancellation));
        }
Example #27
0
 internal void RegisterQueue(IWorkQueue queue)
 {
     lock (Queues)
         Queues.Add(queue);
 }
Example #28
0
 internal void RegisterQueue(IWorkQueue queue)
 {
     lock (Queues)
         Queues.Add(queue);
 }
 public QueueEventProducer(IWorkQueue <IEvent> workQueue, int delayInMilliseconds = 1 * 1000)
 {
     WorkQueue           = workQueue ?? throw new ApplicationException("No work queue was provided");
     DelayInMilliseconds = delayInMilliseconds;
 }
Example #30
0
 public WorkItemAggregatorService(IWorkQueue <TContext> destination) : base(null)
 {
     m_Queue            = new WorkQueue <TContext>(destination.Context);
     m_DestinationQueue = destination;
 }
Example #31
0
 public EventContext(IWorkQueue <IEvent> eventQueue = null, double defaultScheduleTimeIntervalInMilliseconds = 60 * 1000)
 {
     EventQueue  = eventQueue ?? new MemoryEventQueue();
     GlobalClock = new TimeEventProducer(defaultScheduleTimeIntervalInMilliseconds);
 }
Example #32
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="context"></param>
 /// <param name="logger"></param>
 /// <param name="mapper"></param>
 /// <param name="analyticsService"></param>
 /// <param name="recommendationService"></param>
 /// <param name="workQueue"></param>
 public TicketService(ApplicationContext context, ILogger <TicketService> logger, IMapper mapper,
                      IAnalyticsService analyticsService, IRecommendationService recommendationService, IWorkQueue workQueue)
 {
     Logger                = logger;
     Mapper                = mapper;
     ApplicationContext    = context;
     AnalyticsService      = analyticsService;
     WorkQueue             = workQueue;
     RecommendationService = recommendationService;
 }
Example #33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DelayingQueue{TItem}" /> class.
 /// </summary>
 public DelayingQueue(ISystemClock clock = default, IWorkQueue <TItem> @base = default)
     : base(@base ?? new WorkQueue <TItem>())
 {
     _waitingLoopTask = Task.Run(WaitingLoopAsync);
     _clock           = clock ?? new SystemClock();
 }
 public void setup()
 {
     _mockQueue = Substitute.For<IWorkQueue<object>>();
     _subject = new BoundedWorkQueue<object>(_mockQueue, Bound);
 }
Example #35
0
 public SecurityScanWorker(ILogger <SecurityScanWorker> logger, ServiceConfig config, IWorkQueue <ScanRequest> queue, ISecurityScanner scanner, IClientFactory clientFactory,
                           RegistryAuthenticationDecoder authDecoder, IAuthHandler authHandler) : base(logger, config, queue, clientFactory)
 {
     this.scanner     = scanner;
     this.authDecoder = authDecoder;
     this.authHandler = authHandler;
 }
Example #36
0
 public DefaultScheduler(string name, IWorkTaskFactory workTaskFactory, IDownloader downloader, IParserFactory parserFactory, IWorkQueue workQueue)
 {
     Name = name;
     this.workTaskFactory = workTaskFactory;
     this.downloader      = downloader;
     this.parserFactory   = parserFactory;
     this.workQueue       = workQueue;
 }
Example #37
0
 public void Register(IWorkQueue wq)
 {
     Logging.LogManager.Log.Log(LogLevel.DINITDETAIL, "WorkQueueManager: registering queue {0}", wq.Name);
     lock (m_queues) m_queues.Add(wq);
 }