Show / Hide Table of Contents

Class AsyncQueueProcessor<TQueue, TItem>

Base class for hosted service processing items from an async queue

Inheritance
object
BackgroundService
AsyncQueueProcessor<TQueue, TItem>
WebhookDispatcher
WebhookSlowDispatcher
TrackEventSender
Implements
IDisposable
IHostedService
Inherited Members
BackgroundService.StartAsync(CancellationToken)
BackgroundService.StopAsync(CancellationToken)
BackgroundService.Dispose()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: SuperOffice.Threading
Assembly: SoCore.dll
Syntax
public abstract class AsyncQueueProcessor<TQueue, TItem> : BackgroundService, IDisposable, IHostedService where TQueue : IAsyncQueueBase<TItem>
Type Parameters
Name Description
TQueue
TItem

Item in the queue

Remarks

The ExecuteAsync(CancellationToken) method is called by the background service framework, once. It, in turn, delegates to the _queue.ProcessItemsAsync method, which loops until the cancellation token is triggered; if the queue is empty it waits for items to arrive.
The ProcessItemAsync(IAsyncQueueProcessItemContext<TItem>, CancellationToken) abstract method is called for each item in the queue, and must be implemented by derived classes to perform whatever processing the actual items should receive.

Constructors

AsyncQueueProcessor(TQueue, ILogger<AsyncQueueProcessor<TQueue, TItem>>)

Default Constructor

Declaration
protected AsyncQueueProcessor(TQueue queue, ILogger<AsyncQueueProcessor<TQueue, TItem>> logger)
Parameters
Type Name Description
TQueue queue
ILogger<AsyncQueueProcessor<TQueue, TItem>> logger
Remarks

The ExecuteAsync(CancellationToken) method is called by the background service framework, once. It, in turn, delegates to the _queue.ProcessItemsAsync method, which loops until the cancellation token is triggered; if the queue is empty it waits for items to arrive.
The ProcessItemAsync(IAsyncQueueProcessItemContext<TItem>, CancellationToken) abstract method is called for each item in the queue, and must be implemented by derived classes to perform whatever processing the actual items should receive.

Fields

_queue

Base class for hosted service processing items from an async queue

Declaration
protected readonly TQueue _queue
Field Value
Type Description
TQueue
Remarks

The ExecuteAsync(CancellationToken) method is called by the background service framework, once. It, in turn, delegates to the _queue.ProcessItemsAsync method, which loops until the cancellation token is triggered; if the queue is empty it waits for items to arrive.
The ProcessItemAsync(IAsyncQueueProcessItemContext<TItem>, CancellationToken) abstract method is called for each item in the queue, and must be implemented by derived classes to perform whatever processing the actual items should receive.

Methods

ExecuteAsync(CancellationToken)

Base class for hosted service processing items from an async queue

Declaration
protected override Task ExecuteAsync(CancellationToken stoppingToken)
Parameters
Type Name Description
CancellationToken stoppingToken
Returns
Type Description
Task
Overrides
BackgroundService.ExecuteAsync(CancellationToken)
Remarks

The ExecuteAsync(CancellationToken) method is called by the background service framework, once. It, in turn, delegates to the _queue.ProcessItemsAsync method, which loops until the cancellation token is triggered; if the queue is empty it waits for items to arrive.
The ProcessItemAsync(IAsyncQueueProcessItemContext<TItem>, CancellationToken) abstract method is called for each item in the queue, and must be implemented by derived classes to perform whatever processing the actual items should receive.

OuterProcessItemAsync(IAsyncQueueProcessItemContext<TItem>, CancellationToken)

Wrapper for ProcessItemAsync(IAsyncQueueProcessItemContext<TItem>, CancellationToken) to catch exceptions and log them.

Declaration
protected Task OuterProcessItemAsync(IAsyncQueueProcessItemContext<TItem> context, CancellationToken cancellationToken)
Parameters
Type Name Description
IAsyncQueueProcessItemContext<TItem> context
CancellationToken cancellationToken
Returns
Type Description
Task
Remarks

An unhandled exception in ProcessItemAsync(IAsyncQueueProcessItemContext<TItem>, CancellationToken) will exit from the wait-for-cancellation loop within the ProcessItemsAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken) method, and this will permanently terminate the background service. As a result, items will no longer be processed and there is no way to restart it... so we try to guard against that.

ProcessItemAsync(IAsyncQueueProcessItemContext<TItem>, CancellationToken)

Process an item from the queue

Declaration
protected abstract Task ProcessItemAsync(IAsyncQueueProcessItemContext<TItem> context, CancellationToken cancellationToken)
Parameters
Type Name Description
IAsyncQueueProcessItemContext<TItem> context

Context of item to be processed

CancellationToken cancellationToken
Returns
Type Description
Task
Remarks

The ExecuteAsync(CancellationToken) method is called by the background service framework, once. It, in turn, delegates to the _queue.ProcessItemsAsync method, which loops until the cancellation token is triggered; if the queue is empty it waits for items to arrive.
The ProcessItemAsync(IAsyncQueueProcessItemContext<TItem>, CancellationToken) abstract method is called for each item in the queue, and must be implemented by derived classes to perform whatever processing the actual items should receive.

Implements

IDisposable
IHostedService

Extension Methods

EnumUtil.MapEnums<From, To>(From)
Converters.MapEnums<From, To>(From)
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top