About 4 months passed since release of version 1.3, and I’m pleased to introduce the next major release – Hangfire 1.4 with a lot of new features added and a lot of stability improvements made. This is the most important upgrade since version 1.0.

New Configuration

Prior to 1.4, there were a lot of classes that drove the configuration – JobStorage, JobActivator, LogProvider and a couple of others. And it was very hard to explore them – as this approach requires you to dig into documentation, look into different namespaces, etc. I tried to resolve this using extension methods for OWIN’s IAppBuilder interface, however sometimes (for example, in always running mode) OWIN context is not applicable.

GlobalConfiguration class is aimed to solve these issues and provide an entry point for all configuration options (plus allowing you to define custom ones):

GlobalConfiguration.Configuration
    .UseNLogLogProvider()
    .UseAutofacActivator()
    .UseRedisStorage();

OWIN’s IAppBuilder interface extension methods were also updated and now as simple as:

public void Configuration(IAppBuilder app)
{
    app.UseHangfireServer();
    app.UseHangfireDashboard();
}

Previous configuration methods still working, but some of them marked with the ObsoleteAttribute.

Time Zone Support

Time zone support has been added for recurring jobs. It is based on BCL’s TimeZoneInfo class, and the usage is pretty simple:

RecurringJob.AddOrUpdate(() => Console.Write(), "15 18 * * *", TimeZoneInfo.Utc);
// Or
RecurringJob.AddOrUpdate(() => Console.Write(), "15 21 * * *", TimeZoneInfo.Local);
// Or
RecurringJob.AddOrUpdate(
    () => Console.Write(), 
    "15 08 * * *", 
    TimeZoneInfo.FindSystemTimeZoneById("Hawaiian Standard Time"));

By default, UTC is used to schedule recurring jobs, but this will be changed in 2.0 release to correspond other default values of other schedulers. Please note that time zone identifiers don’t match between Windows and non-Windows machines.

Continuations

Continuations allow you to chain multiple jobs together and run one jobs only after another’s completion. This may drastically improve job composition and make your jobs re-usable.

var jobId = BackgroundJob.Enqueue(() => Console.Write("Hello, "));
BackgroundJob.ContinueWith(jobId, () => Console.WriteLine("world!"));

By default, continuation will be enqueued after parent job completion. However, you can create a background job in any other state to implement more complex workflows:

var jobId = BackgroundJob.Enqueue(() => Console.Write("Hello, "));

BackgroundJob.ContinueWith(
    jobId, 
    () => Console.WriteLine("world!"), 
    new ScheduledState(TimeSpan.FromMinutes(1)));

Please note you can’t access parent job’s return value as this requires some architectural changes. Hope this will be implemented in version 2.0.

Redesigned Dashboard

Dashboard was redesigned, new navigation, less colors, more accents. It also became extensible, so you can add new pages and modify navigation menus. Just look at this:

New Dashboard

Hangfire.SqlServer Improvements

There are no more millions of records in the Counter table. All counters are aggregated into the new AggregatedCounter in background in a batched, non-blocking manner. Expiration Manager component was also improved by adding some indexes for tables to prevent unnecessary table scans and record blocking.

And much more!

Please see raw release notes for versions 1.4.0-beta1, 1.4.0-rc1 and 1.4.0-rc2.

Upgrading

This is a minor release (from the API point of view), and there is no breaking changes, except Hangfire.SqlServer schema change, that is transparent due to automatic migrations. However, if you have automatic migration disabled, the following note is for you.

Hangfire.SqlServer schema changed to version 4. Please update it first if you disabled automatic migrations.

New configuration is optional for 1.x, old methods are still here, but marked with the ObsoleteAttribute. Old configuration methods will be removed only in 2.0, so you can postpone the configuration changes.

Subscribe to monthly updates

Subscribe to receive monthly blog updates. Very low traffic, you are able to unsubscribe at any time.

Comments