【发布时间】:2020-05-13 18:07:27
【问题描述】:
我试图创建多个队列,每个队列应该只有一个工人数。 所以我做了下面的代码:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseHangfireDashboard("/scheduler", new DashboardOptions
{
Authorization = new[] { new HangFireAuthorization() },
AppPath = "/"
});
app.UseHangfireServer(new BackgroundJobServerOptions()
{
ServerName = string.Format("{0}:facebookqueue", Environment.MachineName),
Queues = new[] { "facebookqueue" },
WorkerCount = 1
});
app.UseHangfireServer(new BackgroundJobServerOptions()
{
ServerName = string.Format("{0}:googlequeue", Environment.MachineName),
Queues = new[] { "googlequeue" },
WorkerCount = 1
});
RecurringJob.AddOrUpdate<IScheduledJobs>(recurringJobId:
"FacebookExtractorJobYesterday",
methodCall: services => services.RecurringJobYesterday(null,
JobCancellationToken.Null),
cronExpression: cronExp, timeZone: TimeZoneInfo.Local, queue: "facebookqueue");
RecurringJob.AddOrUpdate<IGoogleScheduledJobs>(recurringJobId:
"GoogleExtractorJobYesterday",
methodCall: services => services.RecurringJobYesterday(null,
JobCancellationToken.Null),
cronExpression: cronExp, timeZone: TimeZoneInfo.Local, queue: "googlequeue");
}
上面的代码解决了我的目的,它添加了两个具有不同队列的服务器,每个队列都有一个工人数,这样每个作业都可以在它自己的队列中运行,并且每个队列(服务器)只有一个工人数,相同作业永远不会同时运行两次。
我希望每个作业都应该在它自己的队列(服务器)中排队。
我会非常感谢任何形式的帮助。
【问题讨论】:
标签: asp.net-core hangfire