44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using Managing.Application.Abstractions.Services;
|
|
using Managing.Application.Workers;
|
|
using Managing.Application.Workers.Abstractions;
|
|
using static Managing.Common.Enums;
|
|
|
|
namespace Managing.Api.Workers.Workers;
|
|
|
|
/// <summary>
|
|
/// Represents a worker that watches traders and performs actions based on trading activities.
|
|
/// Inherits from <see cref="BaseWorker{TWorker}"/> where TWorker is <see cref="FeeWorker"/>.
|
|
/// </summary>
|
|
public class TraderWatcher : BaseWorker<FeeWorker>
|
|
{
|
|
private readonly ITradingService _tradingService;
|
|
private static readonly WorkerType _workerType = WorkerType.TraderWatcher;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="TraderWatcher"/> class.
|
|
/// </summary>
|
|
/// <param name="logger">The logger to be used by the worker.</param>
|
|
/// <param name="tradingService">The trading service to monitor trading activities.</param>
|
|
/// <param name="workerService">The worker service to manage worker lifecycle.</param>
|
|
public TraderWatcher(
|
|
ILogger<FeeWorker> logger,
|
|
ITradingService tradingService,
|
|
IWorkerService workerService) : base(
|
|
_workerType,
|
|
logger,
|
|
TimeSpan.FromSeconds(120),
|
|
workerService
|
|
)
|
|
{
|
|
_tradingService = tradingService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Executes the worker's task to watch traders. This method is called periodically based on the worker's configured interval.
|
|
/// </summary>
|
|
/// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
|
|
protected override async Task Run(CancellationToken cancellationToken)
|
|
{
|
|
await _tradingService.WatchTrader();
|
|
}
|
|
} |