Hi, I have made a recurring job in my asp.net core application using HangFire.IO, which trigger after 5 min of interval, here is my C# Code
RecurringJob.AddOrUpdate(() => FullThing (Id, name), Cron.MinuteInterval(5));
Now, I want to
- Firstly, get the state of this recurringJob.
- Secondly, I want to send a message, to all clients using SignalR. like "Hello Recurring job starts" . if the recurringJob are started. mean the state of recurringJob is start.
Thanks.
This is quite simple, if you have understood HangFire & SignalR concepts
You can simply place a function inside your Hangfire Job to call SignalR function inside it, to get state of Hangfire.IO and to send message to all users.
Suppose my recurring job name is : FullThings
Now when HangFire call this function(FullThings), place SignalR Hub Instance inside it and call required function, something like this
public string FullThing()
{
hub = GlobalHost.ConnectionManager.GetHubContext<ClientPushHub>();
hub.Clients.All.SendAlertAboutJob("Started");
//Some code
}
You can also read these articles:
https://www.jerriepelser.com/blog/communicate-status-background-job-signalr/
http://docs.hangfire.io/en/latest/background-processing/tracking-progress.html
http://henriquat.re/server-integration/signalr/integrateWithSignalRHubs.html
Above links may make things more clear about SignalR and Hangfire for you.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly