ubeac / ubeac-api

Source of uBeac .NET Core packages
3 stars 2 forks source link

Implement Background Processing - Recurring Tasks #168

Open ilhesam opened 1 year ago

ilhesam commented 1 year ago

In this phase, We want to implement Recurring Tasks of Background Processing. Hangfire is a popular example of this. How to configure tasks in JSON config files should be like this:

{
  "BackgroundTasks": [
    {
      "Name": "Upcoming Payment Reminder",
      "Type": "TS.PaymentGateway.Services.ScheduledPaymentReminderTask",
      "Start": "07:00:00", // at 7AM
      "Recurring": "1.00:00:00" // everyday 
    }
  ]
}

And interface:

public interface IRecurringBackgroundTask : IDisposable
{
    public Task Process(CancellationToken cancellationToken = default);
    public Task Start(CancellationToken cancellationToken = default);
    public Task Stop(CancellationToken cancellationToken = default);
}

We must create a subclass of .NET built-in Background Service to implement Background Task Management. Also, we need to log background tasks into a MongoDB repository.

The packages will be as follows: