Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

  • List item

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.

  • Retrieve the current state of Server

I want to retrieve current state of JOB server, So I can show is server is on or Off.

  • Retrieve state and enable / disable state of Jobs (Only recurrent).
like image 433
imlim Avatar asked Jan 16 '16 07:01

imlim


1 Answers

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.

like image 100
jtabuloc Avatar answered Sep 20 '22 00:09

jtabuloc