Search code examples
.netignite

apache ignite .net sheduled tasks


Based on the project documentation, there is in java version exists some cron-based scheduling. But i don't find any similar in .net implementation.

My task is to once per day update my cache with long running job. In this case (no build in scheduling features for .net version) i think of creating app, which will run ignite in client mode and update cache with data. And run this app with windows task scheduler.

Is there are a better solutions? Or maybe a good examples?

Solution implemented after answer was recieved:

Used FluentScheduler for scheduling periodicaly jobs. Unfortunately the HangFire I intended to use did not work. If node, which contain current executing scheduler fails or gone ofline for some reasons, then service starts on one of the rest nodes, and no scheduling jobs will be lost.

Scheduler job code

public class CacheUpdateRegistry : Registry
{
    private readonly IIgnite _ignite;

    public CacheUpdateRegistry(IIgnite ignite)
    {
        _ignite = ignite;

        // output to console current node id as example each 2 seconds
        Schedule(() => Console.WriteLine("Recurring on node: + " + _ignite.GetCluster().GetLocalNode().Id)).ToRunNow().AndEvery(2).Seconds();
    }

}

Service code:

public class CacheUpdateSchedulerService : IService
{
        [InstanceResource]
        private readonly IIgnite _ignite;

    public void Init(IServiceContext context)
    {
        Console.WriteLine("CacheUpdateSchedulerService initialized");
        obManager.Initialize(new CacheUpdateRegistry(_ignite));
    }

    // other code removed for brevity

}

Ignite node code:

var services = _ignite.GetServices();
services.DeployClusterSingleton("cacheUpdateScheduler", new CacheUpdateSchedulerService());

Solution

  • Ignite Scheduler API in Java is quite basic and local-only. It has almost nothing to do with Ignite, actually.

    That's why we decided to omit this API on .NET side: same thing can be achieved with Timer class.