imlim
imlim

Reputation: 1637

HangFire Server Enable - Disable manually

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.

Upvotes: 7

Views: 8607

Answers (1)

jtabuloc
jtabuloc

Reputation: 2535

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.

Upvotes: 9

Related Questions