28 lines
772 B
C#
28 lines
772 B
C#
|
|
using System.Linq.Expressions;
|
||
|
|
using Hangfire;
|
||
|
|
|
||
|
|
namespace Books.Api.Infrastructure;
|
||
|
|
|
||
|
|
public class HangfireScheduler(IBackgroundJobClient jobClient, IRecurringJobManager recurringJobManager) : IScheduler
|
||
|
|
{
|
||
|
|
public void EnqueueJob<T>(Expression<Func<T, Task>> methodCall)
|
||
|
|
{
|
||
|
|
jobClient.Enqueue(methodCall);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void EnqueueJob<T>(Expression<Func<T, Task>> methodCall, TimeSpan delay)
|
||
|
|
{
|
||
|
|
jobClient.Schedule(methodCall, delay);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void EnqueueJob(Expression<Func<Task>> methodCall)
|
||
|
|
{
|
||
|
|
jobClient.Enqueue(methodCall);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void AddOrUpdateScheduledJob<T>(string title, Expression<Func<T?, Task>> methodCall, string cron)
|
||
|
|
{
|
||
|
|
recurringJobManager.AddOrUpdate(title, methodCall, cron);
|
||
|
|
}
|
||
|
|
}
|