我们的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服务器?
是否有任何方法可以配置Hangfire客户端而无需启动Hangfire服务器是否在同一进程中?
是的,据我所知,对于客户端模块,您只需要像这样创建BackgroundJobClient
:
IBackgroundJobClient client = new BackgroundJobClient(new SqlServerStorage(yourConnectionString)) ;
// or any overload of the SqlServerStorage constructor.