github HangfireIO/Hangfire v0.6
0.6

latest releases: v1.7.37, v1.8.12, v1.8.11...
10 years ago

What's new?

New Client API

Brand new Client API, based on lambda expressions. With this change, you don't even need to define custom job classes. You are able to invoke your existing methods asynchronously while maintaining persistence and transparency.

Two types of methods are supported: static and instance. Static methods will be simply called on the server side (without instance activation). To call instance methods, server will create an instance of the method's class first using the JobActivator class.

public class CommentController : Controller
{
    /* Other actions */

    public ActionResult PostComment(string text)
    {
        var id = CommentService.Create(User, text);

        // Static method
        BackgroundJob.Enqueue(() => CheckForSpam(id));
        // Instance method
        BackgroundJob.Enqueue<CommentController>(x => x.SendToModerator(id));

        return RedirectToAction(/* Some action */);
    }

    [NonAction]
    public void SendToModerator(int commentId)
    {
        /* Implementation logic */
    }

    public static void CheckForSpam(int commentId)
    {
        /* Implementation logic (Akismet, etc.) */
    }
}

Breaking changes

  • Lifecycle of the JobActivator class has been changed. Use the JobActivator.SetCurrent method to change it.
  • The signature of the JobActivator.ActivateJob method was changed. It now returns an instance of object instead of an instance of the BackgroundJob class.
  • The JobDescriptor class was removed. You can see all its properties in the *Context classes.
  • The signature of all filter interfaces was changed. Affected IStateChangingFilter, IStateChangedFilter, IClientFilter, IServerFilter.
  • The signature of JobState methods was changed also.

You'll need to change a bit your JobActivator-based and JobFilterAttribute-based classes.

Transition to the new API

The structure of those jobs, that were created with the new API, was changed. Since new API is more flexible, the old one will be deleted to not to confuse new users with several methods of doing the same things. This version does not contain breaking changes related to the Client API, but it was made obsolete and its usage is prohibited.

To make sure that the storage does not contain jobs in the old format, the transition to the new API will be implemented in two stages.

  1. v0.7: Remove the Perform class to prohibit the use of the Old Client API. After removal of the Perform class, you'll need to convert your existing job classes to correspond to the new API. If your storage is still contains old jobs, they will be processed anyway.
  2. Before v1.0: Remove the BackgroundJob.Perform method. All old jobs will be failed during their processing. You'll need to ensure that all old jobs were processing before proceeding to the version 1.0.

Don't miss a new Hangfire release

NewReleases is sending notifications on new releases.