I have a windows service running that monitors folders. When files appear, based on the which folder received the file, it schedules the job on the appropriate SQL Server.
var hangfireConnection = "GetConnectionBasedOnFolderTriggeringEvent";
JobStorage.Current = new SqlServer.SqlServerStorage( hangfireConnection );
... settings for job ...
BackgroundJob.Enqueue(
() => new JobInvoker().Invoke(
jobName,
inputPackage,
null,
Hf.JobCancellationToken.Null )
);
The problem seems to be that BackgroundJob
has a static reference to the first SqlServerStorage
setting used. I’m not sure of this, but glancing at BackgroundJob
in github, it uses a static ClientFactory
expression to do the actual Enqueue()
method, so thinking this is set and never changed.
If I need separate Hangfire ‘environments’ (SQL Server Databases), what is proper way to pull this off?