CommandScheduler 2.2.2
See the version list below for details.
dotnet add package CommandScheduler --version 2.2.2
NuGet\Install-Package CommandScheduler -Version 2.2.2
<PackageReference Include="CommandScheduler" Version="2.2.2" />
paket add CommandScheduler --version 2.2.2
#r "nuget: CommandScheduler, 2.2.2"
// Install CommandScheduler as a Cake Addin #addin nuget:?package=CommandScheduler&version=2.2.2 // Install CommandScheduler as a Cake Tool #tool nuget:?package=CommandScheduler&version=2.2.2
Integrate MediatR with Hangfire
To schedule your commands, execute them parallel with the retry option and monitor them. Hangfire
gives me all these kinds of features but You have to have public
method which You have to pass to Hangifre
method (for example BackgroundJob.Enqueue
). This is a problem – with the mediator pattern You cannot pass the public method of the handler because You have decoupled it from the invoker. So You need a special way to integrate MediatR
with Hangfire
without affecting basic assumptions.
I presented the way of processing commands asynchronously using MediatR
and Hangfire
. With this approach we have:
- Decoupled invokers and handlers of commands.
- Scheduling commands mechanism.
- Invoker and handler of command may be other processes.
- Commands execution monitoring.
- Commands execution retries mechanism.
These benefits are very important during development using an eventual consistency approach. We have more control over command processing and we can react quickly if a problem will appear.
For this, In CommandScheduler
we defined 4 classes:
CommandsScheduler
serializes commands and sends them toHangfire
.CommandsExecutor
responds toHangfire
jobs execution, deserializes commands, and sends them to handlers usingMediatR
.MediatorSerializedObject
wrapper class for serialized/deserialized commands with additional properties – command type and additional description.MediatorExtension
extension methods forIMediator
public class MyMController : Controller
{
private IMediator _mediator;
public MyMicroserviceController(IMediator mediator)
{
_mediator = mediator;
}
[HttpPost]
public async Task<IActionResult> Post([FromBody] TestCommand testCommand)
{
// Executed after a certain time interval
_mediator.Schedule(new Command { Id = 1 }, DateTimeOffset.Now.AddSeconds(5));
// Fire many times on the specified CRON schedule
//_mediator.ScheduleRecurring(new Command { Id = 1 },nameof(Command), CommonCrons.Minutely);
// Executed only once and almost immediately after creation
//_mediator.Enqueue(new Command { Id = 1 });
return Ok();
}
And our commands are scheduled, invoked, and monitored by Hangfire
.
Installation
Install the package via NuGet first:
Install-Package CommandScheduler
Or via the .NET Core command line interface:
dotnet add package CommandScheduler
Either commands, from Package Manager Console or .NET Core CLI, will download and install CommandScheduler and all required dependencies.
The CommandScheduler includes a IServiceCollection.AddCommandsScheduler(Connection, Assembly)
extension method, allowing you to register CommandScheduler.
builder.Services.AddCommandsScheduler(builder.Configuration.GetConnectionString("HangfireConnection"), typeof(Program));
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Hangfire (>= 1.7.31)
- Hangfire.AspNetCore (>= 1.7.31)
- Hangfire.Core (>= 1.7.31)
- Hangfire.SqlServer (>= 1.7.31)
- MediatR (>= 10.0.1)
- MediatR.Extensions.Microsoft.DependencyInjection (>= 10.0.1)
- Newtonsoft.Json (>= 13.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.