使用Hangfire,如何在不启动进程内服务器的情况下配置Web应用程序以使用BackgroundJobClient.Create入队?

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

我们的Web应用程序使用BackgroundJobClient.Create排队工作,但是我们想在单独的Windows服务而不是Web应用程序中处理所有工作。如果我们的Web应用程序启动时未调用builder.UseHangfireServer,则创建新作业会引发以下错误:

System.InvalidOperationException: 
JobStorage.Current property value has not been initialized. 
You must set it before using Hangfire Client or Server API.

似乎在调用AddHangfire(options => ...UseSqlServerStorage(...)之前UseHangfireServer lambda不会运行。作为一种解决方法,我们可以将Web应用程序配置为侦听以某些GUID命名的队列,但这似乎浪费了Web应用程序的资源,因为它可能在Web场中运行多个实例。

是否有任何方法可以配置Hangfire客户端,而无需在同一过程中启动Hangfire服务器?

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

是否有任何方法可以配置Hangfire客户端而无需启动Hangfire服务器是否在同一进程中?

是的,据我所知,对于客户端模块,您只需要像这样创建BackgroundJobClient

IBackgroundJobClient client = new BackgroundJobClient(new SqlServerStorage(yourConnectionString)) ;
// or any overload of the SqlServerStorage constructor.
© www.soinside.com 2019 - 2024. All rights reserved.