MonScheduler 1.0.0

dotnet add package MonScheduler --version 1.0.0
                    
NuGet\Install-Package MonScheduler -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MonScheduler" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MonScheduler" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MonScheduler" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MonScheduler --version 1.0.0
                    
#r "nuget: MonScheduler, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MonScheduler@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MonScheduler&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MonScheduler&version=1.0.0
                    
Install as a Cake Tool

Horarium

Unit Tests Integration Tests Nuget

English | 中文

Horarium is an open source job scheduling .NET library with an easy to use API, that can be integrated within applications of any scale - from the smallest stand-alone application to the largest e-commerce system.

Horarium is fully based on an asynchronous work model, it allows you to run hundreds of parallel jobs within a single application instance. It supports jobs execution in distributed systems and uses MongoDB as a synchronization backend.

Horarium supports .NET Core/netstandard 2.0 and .NET Framework 4.6.2 and later.

Support Databases

Database Support
MongoDB Yes
In Memory Yes

Getting started

Add nuget-package Horarium

dotnet add package Horarium
dotnet add package Horarium.Mongo

Add job that implements interface IJob<T>

public class TestJob : IJob<int>
{
    public async Task Execute(int param)
    {
        Console.WriteLine(param);
        await Task.Run(() => { });
    }
}

Create HorariumServer and schedule TestJob

var horarium = new HorariumServer(new InMemoryRepository());
horarium.Start();
await horarium.Create<TestJob, int>(666)
        .Schedule();

Add to Asp.Net core application

Add nuget-package Horarium.AspNetCore

dotnet add package Horarium.AspNetCore

Add Horarium Server. This regiters Horarium as a hosted service, so .Net core runtime automatically starts and gracefully stops Horarium.

public void ConfigureServices(IServiceCollection services)
{
    //...
    services.AddHorariumServer(MongoRepositoryFactory.Create("mongodb://localhost:27017/horarium"));
    //...
}

Inject interface IHorarium into Controller


private readonly IHorarium _horarium;

public HomeController(IHorarium horarium)
{
    _horarium = horarium;
}

[Route("api")]
public class HomeController : Controller
{
    [HttpPost]
    public async Task Run(int count)
    {
            await _horarium.Create<TestJob, int>(count)
                          .Schedule();
    }
}

Create Recurrent Job

Add job that implements interface IJobRecurrent

public class TestRecurrentJob : IJobRecurrent
    {
        public Task Execute()
        {
            Console.WriteLine("Run -" + DateTime.Now);
            return Task.CompletedTask;
        }
    }

Schedule TestRecurrentJob to run every 15 seconds

await horarium.CreateRecurrent<TestRecurrentJob>(Cron.SecondInterval(15))
                .Schedule();

Create sequence of jobs

Sometimes you need to create sequence of jobs, where every next job would run if and only if previous job succeeds. If any job of the sequence fails next jobs won't run

await horarium
    .Create<TestJob, int>(1) // 1-st job
    .Next<TestJob, int>(2) // 2-nd job
    .Next<TestJob, int>(3) // 3-rd job
    .Schedule();

Distributed Horarium

Horarium has two types of workers: server and client. Server can run jobs and schedule new jobs, while client can only schedule new jobs.

Horarium guarantees that a job would run exactly once

Things to watch out for

Every Horarium instance consults MongoDB about new jobs to run every 100ms (default), thus creating some load on the DB server. This interval can be changed in HorariumSettings

If you want to decrease load, you can use job throttling that will automatically increase interval if there are no jobs available after certain attempts. To enable this feature, pass JobThrottleSettings to HorariumSettings with property UseJobThrottle set to true.

var settings = new HorariumSettings
{
    JobThrottleSettings = new JobThrottleSettings
    {
        UseJobThrottle = true
    }
};

For more information about configuration, see JobThrottleSettings

Using Horarium with SimpleInjector

To use Horarium with SimpleInjector one should implement its own IJobFactory, using Container from SimpleInjector. For example:

public class SimpleInjectorJobScopeFactory : IJobScopeFactory
{
    private readonly Container _container;

    public SimpleInjectorJobScopeFactory(Container container)
    {
        _container = container;
    }

    public IJobScope Create()
    {
        var scope = AsyncScopedLifestyle.BeginScope(_container);
        return new SimpleInjectorJobScope(scope);
    }
}

public class SimpleInjectorJobScope : IJobScope
{
    private readonly Scope _scope;

    public SimpleInjectorJobScope(Scope scope)
    {
        _scope = scope;
    }

    public object CreateJob(Type type)
    {
        return _scope.GetInstance(type);
    }

    public void Dispose()
    {
        _scope.Dispose();
    }
}

Then add HorariumServer (or HorariumClient):

container.RegisterSingleton<IHorarium>(() =>
{
    var settings = new HorariumSettings
    {
        JobScopeFactory = new SimpleInjectorJobScopeFactory(container),
        Logger = new YourHorariumLogger()
    };

    return new HorariumServer(jobRepository, settings);
});

In case of HorariumServer, don't forget to start it in your entypoint:

((HorariumServer) container.GetInstance<IHorarium>()).Start();

Failed repeat strategy for jobs

When a job fails, Horarium can handle this exception with the same strategy. By default, the job repeats 10 times with delays of 10 minutes, 20 minutes, 30 minutes and etc. You can override this strategy using IFailedRepeatStrategy interface.

Example of default DefaultRepeatStrategy implementation:

public class DefaultRepeatStrategy :IFailedRepeatStrategy
{
    public TimeSpan GetNextStartInterval(int countStarted)
    {
        const int increaseRepeat = 10;
        return TimeSpan.FromMinutes(increaseRepeat * countStarted);
    }
}

This class is called every time when a job fails, and it has to return TimeSpan of the next scheduled job run. To override default behavior globally, change settings in HorariumSettings

new HorariumSettings
{
    FailedRepeatStrategy = new CustomFailedRepeatStrategy(),
    MaxRepeatCount = 7
});

To override the default behavior for a particular job:

await horarium.Create<TestJob, int>(666)
    .MaxRepeatCount(5)
    .AddRepeatStrategy<DefaultRepeatStrategy>()
    .Schedule();

If you want to disable all repeats, just set MaxRepeatCount to 1

new HorariumSettings
{
    MaxRepeatCount = 1
});
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on MonScheduler:

Package Downloads
MonScheduler.Mongo

MonScheduler.Mongo is the .Net library to support MongoDB in Horarium

MonScheduler.AspNetCore

MonScheduler.AspNetCore is the .Net library to support Asp .Net Core in Horarium

MonScheduler.InMemory

MonScheduler.InMemory

Horarium.InMemory

Package Description

Horarium.Sample

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 184 8/8/2025