HangFire 0.8.2 released

Please, see the corresponding blog post for the details. Here is the short list of changes:

  • Added - Batch operations on jobs for HangFire Monitor.
  • Added - Retry and delete buttons for almost every page of HangFire Monitor.
  • Added - Duration and latency metrics for succeeded jobs.
  • Added - Display state transition latencies on job details page.
  • Added - DisableConcurrentExecution filter.
  • Misc - Tables in HangFire Monitor received some love.

Great job. :smile:
Do you have an idea when the job cancellation will implemented?

What kind of cancellation do you mean? If you don’t want to discard a job, you can delete it. If you have long-running job and want to abort it, you should wait for a while :smile:

Hm, no, you can implement abort with yourself, I’ll show you how, if you need it.

I need to abort Jobs, yes. If you can show me how that would be great! :smile:

I assume your job is using a loop, and you want to break it once a user requested job abort. And I assume that the method has a parameter for identifier of interruptible work. In this case you can add a column, say Canceled to your entity and check its value on each iteration. This will add some delays, but it is required to use shared storage here to pass the job cancellation.

The example below uses some kind of EntityFramework, but I forgot all its method names :smile:

public void SendMail(int mailListId)
{
    var mailList = _context.MailLists.Find(mailListId);
    foreach (var email in mailList.Emails)
    {
        // We need to always get the freshest value, not the cached one.
        context.Refresh(RefreshMode.StoreWins, yourEntity);
        if (mailList.Canceled)
        {
            return;
        }
        _service.Send(email);
    }
}

To cancel a job, you should set the Canceled column value to true. If you want to see the job in the Deleted state, then just delete it. Otherwise it will be moved to the Succeeded state, that can be confusing a bit.

public void Cancel()
{
    var mailList = _context.MailLists.Find(id);

    BackgroundJob.Delete(mailList.JobId);
    mailList.Canceled = true;

    _context.SaveChanges();
}

Mmm? https://github.com/odinserj/HangFire/pull/103

@kozalla, howdy? You now have a more simple way to cancel jobs, check HangFire 0.8.3.

Job cancellation on Hangfire shutdown is exactly the feature I needed!
Great job! :slight_smile:

Thanks. What problems have you encountered without cancellation on shutdown? Long application shutdown time, 30-minute latency after application restart due to InvisibilityTimeout or both?

If I have to deploy a new version and the database context will change while a job is running I will run in to Problems. And it would be very uncomfortable to wait until the jobs have completed :smile: