I have a webapp and I’m trying to use Hangfire to offload processing of large reports onto a second server. I’m planning to use some kind of MQ to avoid latency.
- User loads App1 report page, configures parameters, clicks “Run”.
- The parameters are serialized to JSON and passed to a method on a SignalR hub in App1.
- ReportHub.Queue(string params) calls BackgroundJob.Enqueue(r => r.Process(params)
- App2 on a different server picks up the IBackgroundReports job, instantiates class BackgroundReports:IBackgroundReports, calls Process(string)
- ???
- Event raised in App1, sends download path as SignalR message to client
- JS callback on SignalR client triggers download of file.
- Profit!
From the sourcecode I can’t see whether ContinueWith jobs are handled immediately within the same worker that completes the parent job, or if the parent job completion just triggers a state change Awaiting->Enqueued in the child which would allow it to be picked up by a worker in a different App.
Workarounds:
- App1 could use a SQL Service Broker table dependency to watch for updates in the [HangFire].[Job] table. I’m on a shared SQL Server farm, this could get political.
- A continuewith for the report job enqueues a Notification job that is only processed by App1. Woo, more jobs.
- A continuewith that MQs the job ID back to App1. I’m not yet using MQ directly.
- A new feature for Hangfire.SqlServer.Msmq to allow apps to subscribe to state changes.