During development of HangFire application with C# ASP.NET, and I decided to implement functionally where Admin can manage state of Server, jobs.
Server Enable Disable state. Using Enable Button click event Admin can start JOB server so all the Fire and Forget and Recurrent job can performed. And Disable button stop all the activities of JOB.
I want to retrieve current state of JOB server, So I can show is server is on or Off.
If you want to manage Server/Job created by Hangfire, you can use MonitoringApi or JobStorage to get there statuses.
Sample Codes :
var _jobStorage = JobStorage.Current;
// How to get recurringjobs
using (var connection = _jobStorage.GetConnection())
{
var storageConnection = connection as JobStorageConnection;
if (storageConnection != null)
{
var recurringJob = storageConnection.GetRecurringJobs();
foreach(var job in recurringJob)
{
// do you stuff
}
}
}
// How to get Servers
var monitoringApi = _jobStorage.GetMonitoringApi();
var serverList = monitoringApi.Servers();
foreach( var server in serverList)
{
// do you stuff with the server
// you can use var connection = _jobStorage.GetConnection()
// to remove server
}
From here you can play around with Hangfire.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With