HangFire Server Enable - manually disable

During the development of HangFire applications with C # ASP.NET, and I decided to implement it functionally, where Admin can manage server status, tasks.

  • List item

Turn on the server. Disable state. Using the "Enable button" button click event Admin can start the JOB server, so all Fire and Forget and Recurrent actions can be performed. The Disable button stops all JOB actions.

  • Get current server status

I want to get the current state of the JOB server, so I can show that the server is on or off.

  • Restore state and enable / disable task state (only recursively).
+4
source share
1 answer

If you want to manage the server / job created by Hangfire, you can use MonitoringApi or JobStorage to get statuses.

Code Examples

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 with Hangfire.

+6
source

Source: https://habr.com/ru/post/1624550/


All Articles