ServiceStack.Quartz


Getting Started Edit on GitHub


Note! Uses Quartz.Net v3.x which requires net 4.52 and above.

Install the nuget package into your ServiceStack AppHost project


install-package ServiceStack.Quartz

Create a basic job


public class MyJob : IJob
{
    public Task Execute(IJobExecutionContext context)
    {
        // ... job code goes here
        return context.AsTaskResult();
    }
}

Then inside your AppHost, register the plugin and a job trigger.


public class AppHostSample : AppHostBase
{
    public AppHostSample() : base("Quartz Sample", typeof(MyServices).Assembly)
    {
    }

    public override void Configure(Container container)
    {
        var quartzFeature = new QuartzFeature();

        // create a simple job trigger to repeat every minute 
        quartzFeature.RegisterJob<MyJob>(
            trigger =>
                trigger.WithSimpleSchedule(s =>
                        s.WithInterval(TimeSpan.FromMinutes(1))
                            .RepeatForever()
                    )
                    .Build()
        );

        // register the plugin
        Plugins.Add(quartzFeature);
    }
}

That's it. The job will now execute every minute while the apphost is running.

Defaults

Jobs

By default, the plugin will scan all assemblies for implementations of Quartz.Net's IJob interface and register them with ServiceStack's IoC container.

Your IJob implementations will use the IoC container to resolve any constructor or property injection dependencies automatically.

Configuration

By default, the plugin will use the standard Quartz.Net's configuration (if specified).

Lifecycle

By default, the scheduler is started after the the AppHost has initialised and shutdown when the AppHost is disposed.

Persistence

By default, there is no scheduler persistence for Jobs. This can be configured using the standard Quartz.Net configuration options.