标签: hangfire-console

如何强制hangfire服务器在重新启动时删除该特定服务器的旧服务器数据?

我正在显示当前在我的页面上运行的hangfire服务器列表.

我在控制台应用程序中运行hangfire服务器,但问题是当我没有运行我的控制台应用程序仍然hangfire api返回hangfire服务器.

此外,当我跑我的控制台应用程序多次,我得到3-4迟发型服务器虽然我只有1迟发型服务器控制台应用程序运行.

Mvc申请:

IMonitoringApi monitoringApi = JobStorage.Current.GetMonitoringApi();
var servers = monitoringApi.Servers().OrderByDescending(s => s.StartedAt);
Run Code Online (Sandbox Code Playgroud)

控制台应用程序:Hangfire服务器

public static void Main(string[] args)
{
    var sqlServerPolling = new SqlServerStorageOptions
    {
        QueuePollInterval = TimeSpan.FromSeconds(20) // Default value
    };
    GlobalConfiguration.Configuration.UseSqlServerStorage("ConnectionString", sqlServerPolling);

    // Set automatic retry attempt
    GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 });

    // Set worker count
    var options = new BackgroundJobServerOptions
    {
        WorkerCount = 1,
    };
    using (var server = new BackgroundJobServer(options))
    {
        Console.WriteLine("Hangfire Server1 started. Press any key to exit...");
        Console.ReadKey();
    } …
Run Code Online (Sandbox Code Playgroud)

c# hangfire hangfire-console

10
推荐指数
1
解决办法
1646
查看次数

标签 统计

c# ×1

hangfire ×1

hangfire-console ×1