Hangfire 排队作业未运行

问题描述 投票:0回答:1

我的作业正在排队,但未执行。

BackgroundJob.Enqueue<MasterDataMessageConsumerJob>(nameof(MasterDataMessageConsumerJob).ToLower(), x => x.ExecuteAsync(CancellationToken.None));

我可以看到该作业在仪表板中排队,但它从未运行。

但是,如果我通过

RecurringJob.AddOrUpdate
使用相同的代码,则作业会被添加并执行得很好;

RecurringJob.AddOrUpdate<MasterDataMessageConsumerJob>(nameof(MasterDataMessageConsumerJob), x  => x.ExecuteAsync(CancellationToken.None), Cron.Minutely())

这是在 ASP.NET Core 中,我直接在

program.cs

中实现了服务器,如下所示
        builder.Services.AddHangfire(configuration => configuration
            .UseSimpleAssemblyNameTypeSerializer()
            .UseRecommendedSerializerSettings()
            .UseSqlServerStorage(builder.Configuration.GetConnectionString("MyDbServer")));

        // Add the processing server as IHostedService
        builder.Services.AddHangfireServer();

        // configure the DI for generic data and master data services
        ConfigureDIServices(builder.Services);

        var app = builder.Build();

        app.UseHangfireDashboard("/dashboard");

        // run the master data message consumer hourly, which will internally enqueue the continuation jobs
        BackgroundJob.Enqueue<MasterDataMessageConsumerJob>(nameof(MasterDataMessageConsumerJob).ToLower() + "2",
                                                            x => x.ExecuteAsync(CancellationToken.None));

有人能看到我错过了什么吗?


更新

我在拨打

static
Console.Writeline
时也遇到同样的问题。它已排队但未运行,因此这让我更有信心我一定设置了错误。

BackgroundJob.Enqueue("masterdatamessageconsumerjob42 ", () => Console.WriteLine("Write something here"));

example of a queued job that is not executed

asp.net-core hangfire
1个回答
0
投票

我找到了一个对我有用的答案 - 从

nameof(MasterDataMessageConsumerJob).ToLower() + "2"
方法中删除“QueueName”参数
Enqueue

BackgroundJob.Enqueue<MasterDataMessageConsumerJob>(x => x.ExecuteAsync(CancellationToken.None));

也许这是一个专业功能?我在文档中找不到任何有关它的内容。

© www.soinside.com 2019 - 2024. All rights reserved.