Hangfire Discussion

Query all jobs with job data?


#1

Hi,

is it possible to query all available recurring jobs from the server to get class name and job parameters?

Thanks!


#2

What do you mean by available? If you are using SQL Server, you can query the [Set] table where Key column = ‘recurring-jobs’. That will get you all of the function names. If you wanted the job data from there, you’d have to query the [Hash] table where the key is ‘recurring-job:JOBNAME’ where JOBNAME is the [Value] from the row in the [Set] table. That [Hash] table row will also have a [Value] column which is the serialized job including method information and parameters. Here’s the queries the dashboard uses for SQL Server: here


#3

Yes, that’s querying the database directly - sure I could do that.

I asked for an API or function call to have a standardized interface.


#4

Look at the MonitoringAPI.

var api = JobStorage.Current.GetMonitoringApi();
var scheduledJobs = api.ScheduledJobs(0,100);

Should be what you need.


#5

Sorry, your question specifically said query so I was assuming you wanted to query outside of the application. If you’re wanting to do this inside your application, again depending on what you mean by “available”, you should be able to use the link I posted earlier which is a static method on IStorageConnection. You should be able to call it like this: JobStorage.Current.GetConnection().GetRecurringJobs();
That returns a List of RecurringJobDto

Check out the code including overloads here

From there you should have access to a Job property of type Job which has the info you are looking for.


#6

be aware, though, that the monitoring api is actually deserializing the jobs when you query for it, so the code that is inspecting the jobs needs to have the full job implementation available.

I once tried to make a small command line application to inspect a hangfire instance, but had to give up since the assemblies containing the jobs was not available for the command line app…

So in that case, querying the database is the only option…