Send message to all clients if a recurringJob in hangfire is started using SignalR in .net core2


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.


Asked by:- LuneAgile
0
: 4750 At:- 11/26/2018 12:16:46 PM
ASP.NET SignalR HangFire.IO







1 Answers
profileImage Answered by:- neena

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.

3
At:- 11/26/2018 3:01:12 PM Updated at:- 11/26/2018 3:01:31 PM
Thanks so much neena. 0
By : LuneAgile - at :- 11/26/2018 7:34:04 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use