VirtualLife
VirtualLife

Reputation: 402

Updating a client regularly(scheduled) and on demand via signalR

I am building something that is using SignalR to push data to the client, this is working properly. What I am debating on is how to handle doing the push.

Data can be pushed via regular schedule (ie 5pm every day), or if a user goes to the site and clicks push now, it will send the data immediately.

Should I create a background application that is in an infinate loop deciding if a push needs to be sent (sounds like a waste of cpu and a challenge considering I have a shared host, not an owned server)? For the most part, everything can be database driven if there is a way to hook into a data on change event. At the same time, I don't fully trust sql triggers and being shared atm, I can't turn on clr. This will be for a fairly large number of connected machines eventually(easily 250k+ concurrently), so efficiency is a concern.

Note: the core of the site is built in mvc .net.

Upvotes: 1

Views: 332

Answers (1)

Winner Crespo
Winner Crespo

Reputation: 1704

You could create a CronJob to do this. You could use this one, the Azure WebJobs or another one.

EDIT: Let me help you a little bit more, I've working in this scenario many times before, and it is something that is common in many applications.

First, you should create a method controller that, when triggered, the desired effect should happen in the applications. An example of this would be a controller method that every time it is called, updated some entries in a database.

After you've wrote the controller, TEST IT. Make sure everything work as expected. This is a very critical point if you are WRITING data to the database, as the action is going to happen automatically.

Then, read about Cronjobs, or webjobs. They are basically a call to a URL, which can be set in a timely manner. For example, you could create a cronjob that goes to http://yoursite.com every minute, o every week.

Finally, create a Cronjob that calls your controller method. (You won't be able to test a cronjob if your application is not published though, test the method locally by typing the controller url in the browser's bar)

Upvotes: 2

Related Questions