Hangfire vs Quartz.net - not run on public holidays


#1

Hi, We are currently using Quartz.net for our scheduling. I was thinking of switching over to Hangfire for the dashboard and in built support for rerunning jobs. One feature I can’t seem to find is ability to not run jobs on certain days like public holidays. We have built calendars that tell Quartz which days to exclude from the list of available days.

Also is it possible to get the last runtime for this job from the job itself?


#2

Hi, is there any update about this issue?


#3

While not available out of the box the idea of Hangfire is to allow you to add your own attributes and filters that will allow you to implement what you want. You can ‘inject’ such custom logic at different stages of the process.

I suggest you look at this page in particular to get you started: Using Job Filters

As to the question ‘can you get the last runtime’ the answer is a little more complex. Short answer is yes. You can get that information as follows :

JobStorage.Current.GetConnection().GetRecurringJobs()

Of course this only works if you have already configured you jobstorage and connection to your database where you store the hangfire data. It will return a IEnumerable<RecurringJobDto> with all your current recurring jobs including a LastExecution and NextExecution property. What you have to keep in mind though is that this information is not ‘realtime’. It might take a while for the values to be updated so using it from within the job is probably not going to be achieving the result you want.

Again (judging from your post) you probably will want to implement some custom job tracking logic of your own from within the JobFilters that does not depend on LastExecution at all.