Beispiel #1
0
        public async Task QueueLenghtReported(int length)
        {
            await semaphore.WaitAsync().ConfigureAwait(false);

            try
            {
                if (length > maxLength && tokenSource != null)
                {
                    log.Info($"Stopping sending messages to {destination} as the current queue length ({length}) is over the defined threshold ({maxLength}).");
                    tokenSource.Cancel();

                    try
                    {
                        await generationTask.ConfigureAwait(false);
                    }
                    catch (OperationCanceledException)
                    {
                        //Ignore
                    }
                    catch (Exception e)
                    {
                        log.Error("Error stopping generating of messages", e);
                    }

                    tokenSource.Dispose();
                    tokenSource    = null;
                    generationTask = null;
                    return;
                }
                if (length < minLength && tokenSource == null)
                {
                    log.Info($"Starting sending messages to {destination} as the current queue length ({length}) is under the defined threshold ({minLength}).");
                    tokenSource    = new CancellationTokenSource();
                    generationTask = Task.Run(() => generateMessages(destination, tokenSource.Token), tokenSource.Token);
                }
            }
            finally
            {
                semaphore.Release();
            }
        }
Beispiel #2
0
 public void Begin()
 {
     _log.Info("UoW begin");
 }