⚠️ Deprecated —SolTechnology.Core.Scheduleris deprecated in favour of SolTechnology.Core.Hangfire recurring jobs. See background-processing architecture.
The SolTechnology.Core.Scheduler library provides minimum functionality needed for scheduled background tasks. It handles needed services registration and configuration. It is based on Hangfire.Cronos library. The service is using in-memory scheduler, so does not share the scheduling information between instances.
For installing the library, reference SolTechnology.Core.Scheduler nuget package and invoke AddScheduledJob() service collection extension method:
services.AddScheduledJob<SynchornizeCristianoRonaldoMatches>();- The first option is to create an appsettings.json section:
"Configuration": {
"ScheduledJobs": [
{
"JobName": "SynchornizeCristianoRonaldoMatches",
"CronExpression": "0 0 * * *"
}
]
}In this case, JobName has to match registered service (T) name.
- Alternatevely the same settings can be provided by optional parameter during registration:
builder.Services.AddScheduledJob<SynchornizeCristianoRonaldoMatches>(new ScheduledJobConfiguration("0 0 * * *")); //every day at midnight- Derivate from ScheduledJob base class
public class SynchornizeCristianoRonaldoMatches : ScheduledJob- Implement constructor and Execute() method
public SynchornizeCristianoRonaldoMatches(
ISchedulerConfigurationProvider schedulerConfigurationProvider,
IServiceScopeFactory serviceScopeFactory,
ILogger<ScheduledJob> logger)
: base(schedulerConfigurationProvider, serviceScopeFactory, logger)
{
var scope = serviceScopeFactory.CreateScope();
var handler = scope.ServiceProvider.GetRequiredService<ICommandHandler<SynchronizePlayerMatchesCommand>>();
_handler = handler;
}
public override async Task Execute()
{
await _handler.Handle(new SynchronizePlayerMatchesCommand(44));
}- The job will run based on provided Cron expression.