mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2025-12-30 01:18:36 -05:00
33 lines
771 B
C#
33 lines
771 B
C#
using Infrastructure.Verticals.Jobs;
|
|
using Quartz;
|
|
using Serilog.Context;
|
|
|
|
namespace Executable.Jobs;
|
|
|
|
[DisallowConcurrentExecution]
|
|
public sealed class GenericJob<T> : IJob
|
|
where T : IHandler
|
|
{
|
|
private readonly ILogger<GenericJob<T>> _logger;
|
|
private readonly T _handler;
|
|
|
|
public GenericJob(ILogger<GenericJob<T>> logger, T handler)
|
|
{
|
|
_logger = logger;
|
|
_handler = handler;
|
|
}
|
|
|
|
public async Task Execute(IJobExecutionContext context)
|
|
{
|
|
using var _ = LogContext.PushProperty("JobName", typeof(T).Name);
|
|
|
|
try
|
|
{
|
|
await _handler.ExecuteAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "{name} failed", typeof(T).Name);
|
|
}
|
|
}
|
|
} |