gpt4 book ai didi

c# - HangFire 服务器启用 - 手动禁用

转载 作者:太空狗 更新时间:2023-10-29 21:26:56 24 4
gpt4 key购买 nike

HangFire 的开发过程中使用 C# ASP.NET 的应用程序,我决定实现管理员可以管理服务器状态和作业的功能。

  • 列表项

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.

  • 检索状态并启用/禁用作业状态(仅限循环)。

最佳答案

如果你想管理由 Hangfire 创建的服务器/作业,你可以使用 MonitoringApi 或 JobStorage 来获取那里的状态。

示例代码:

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
}

从这里您可以尝试使用 Hangfire。

关于c# - HangFire 服务器启用 - 手动禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34824446/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com