Hangfire - 具有指定队列名称的重复作业

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

我有两台服务器,ServerA 和 ServerB。他们共享相同的hangfire 数据库。 我有两份工作,JobA 和 JobB。

在 ServerA 上,我使用:

RecurringJob.AddOrUpdate(
            "JobA",
            () => new JobA().Execute(),
            this._configuration.Schedule, queue: "A");

在ServerB上,我使用:

  RecurringJob.AddOrUpdate(
            "JobB",
            () => new JobB().Execute(),
            this._configuration.Schedule, queue: "B");

问题是每个作业都“入队”在“Job”表中,它们永远不会被执行。

如果我在“AddOrUpdate”方法中删除队列覆盖,则会执行作业(显然没有配置队列)。

还缺什么吗?如何使用队列配置来配置重复作业?

hangfire
2个回答
3
投票

代码丢失...

服务器A:

var options = new BackgroundJobServerOptions
{
  Queues = new[] { "A" }
};

this._backgroundJobServer = new BackgroundJobServer(options);

服务器B:

var options = new BackgroundJobServerOptions
{
  Queues = new[] { "B" }
};

this._backgroundJobServer = new BackgroundJobServer(options);

2
投票

解决方案 - 可能会帮助有类似问题的人:

app.UseHangfireServer(new BackgroundJobServerOptions
{
     // queue name must be in lowercase
     Queues = new[] { "qname" } //This will setup the server to only process qname queues 
});

RecurringJob.AddOrUpdate(
    () => new JobB().Execute(),
    Cron.Hourly(5),
    null,
    "qname");
© www.soinside.com 2019 - 2024. All rights reserved.