bazzy
July 26, 2016, 1:51pm
1
Hello, is it possible for an observer to listen for finished Hangfire jobs? Something like this:
Process A (Web Service): Enqueue a job to execute in 5 minutes
Process B (Windows Service): Be notified of this job’s completion and take some action
Can anyone help? Thank you
You can use continuations:
var jobId = BackgroundJob.Schedule( ... , 5 mins); BackgroundJob.ContinueWith( jobId, continuation );
dmehta
July 27, 2016, 5:14pm
3
If you are looking for a generic solution, you can implement IElectStateFilter and within OnStateElection method, you can handle Succeeded or Failed state to take whatever action you need to perform.
bazzy
July 27, 2016, 6:07pm
4
Would I be able to use my IElectStateFilter from a completely separate .NET process hosted on another machine?
dmehta
July 27, 2016, 6:31pm
5
Yes, I implemented it in a windows service that host the Hangfire Server and it runs on a different machine than the web application that en-queues the job
1 Like
bazzy
July 27, 2016, 6:33pm
6
Thank you so much for the suggestion; it sounds very promising. I will give it a shot!
bazzy
July 28, 2016, 5:41pm
7
This works great, thank you. I have another question, if you don’t mind.
Do you know of a way to broadcast a job’s state change to multiple servers?
Client App: Enqueue the job
Server1 App: Use filter to become notified
Server2 App: Use filter to become notified
So in essence, both server apps are notified by the same job’s completion?