Define an on-demand job in HangFire

In Hangfire, I successfully install recurring jobs and can start manually if I want, thanks to the web interface and its trigger button.

RecurringJob.AddOrUpdate(..); 

enter image description here

But I'm ready to set up a task that never starts automatically. Only on request from WebUi. Think of it as a set of maintenance tasks that run only when necessary. Manually.

I was thinking about adding a non-reccuring Job to a wait state, but I couldn’t (and it sounds wrong).

Are On Demand Jobs possible with Hangfire?

+8
source share
4 answers

I use this CRON expression as Never: 0 0 29 2/12000 WED At midnight, February 29th, which happens on Wednesday, every century.

As @youen found out, this expression gives a later date. "0 0 29 2/12000 PN"

+6
source

The main trunk is not yet implemented manually or "on request". However, you can use this plug to have this option.

This is currently marked as working in the Hangfire repo , and you can use it like this:

 BackgroundJob.Stash(() => Console.WriteLine("STASHING")); 

Another approach mentioned in one of the comments is that there is a button on your site that queues the task:

 BackgroundJob.Enqueue(() => Console.WriteLine("Simple!")); 

EDIT: 2017/12/28:

Apparently, the previous fork will not be merged, since this extension already supports manual queue jobs:

Hangfire.Core.Dashboard.Management

enter image description here

+3
source

Yes, jobs on demand are quite possible with hangfire. You can run fire-and-forget missions using the following:

 BackgroundJob.Enqueue( () => Console.WriteLine("Simple!")); 

However, this will not appear on the hangfire control panel, but you can use the code snippet above (maybe after clicking the button?)

+2
source

I used this (hangfire 1.7 on .net 4.6.2)

 RecurringJob.AddOrUpdate(() => ..., "0 0 31 2 0"); 

It is displayed on the toolbar as:

Next version N / A

0
source

All Articles