1

I have an ASP.NET API method when the client call this method I am going to run 4 tasks each task go and call a url collect data and return it back as a List of objects. now each task take different time to complete so what I am looking for is like this.

  • javascript AJAX call my API method
  • The API method run 4 tasks and wait any completed task and return data
  • The ajax call back the API again and see which tasks completed and take the data again and display it on the browser

Now my solution for this is to save the data returned from the tasks in memory database line couchbase then let a timer on the browser call the API to check if there is any new data has been added and then take it till all the tasks completed.

My question is. Is there is any other solutions for this. I do not want to use asp.net signalr

In order to make my idea clear here what I have in my mind

  • The client call the API Method
  • The API method en queue a list of tasks to hangfire
  • Each job will go call another APIs get data process it and log it to memory database I will use couchbase
  • When the My API method finish logging the jobs its return a key to the client
  • The client can use this key to call another API method which return for him the recent data

This solution is for this problem

  • I have an API method which go search for hotels using multiple hotels providers
  • Each provider return data which I need later to process this data and return it to the client.
  • Since each provider has its own processing time. some provider give me response after 5 sec and some other providers 30sec and some of them even more.
  • I do not want the client to wait all the provider to finish instead I want the client to get result as soon as possible to display it on the browser then i can update the UI each time I go and check if there is new provider has finish returning data to me
mhdbaz
  • 67
  • 9
  • I've not done much ajax, but as I understand it it's inherently asynchronous. Don't you kisk off a task and provide a callback that is invoked when a response from the server is received? That being the case why does it matter that the server processing takes a while? – Ian Jun 30 '16 at 15:20
  • I can provide only a call back when the first tasks completed. lets say I am running 4 tasks async. when the first one done i can return data to the client. I do not want to wait for all of them to completed in order to return data otherwise lets say one of the tasks will take 30 sec and the others each one will take 1 sec in this case the client should wait 30 sec in order to see data. what I am looking for is return data after 1 sec then keep asking the server for new data. – mhdbaz Jun 30 '16 at 15:40
  • You have not specified your requirements clearly and completely. – Ian Jun 30 '16 at 18:12
  • 1
    If you are not going to use a push notification (SignalR) - then you will have to manually poll the API from the client. Once your return "something" to the client from API method - the cycle has completed. You no longer have request context to respond to. So you will either need to manually poll from the client or push from the server. Since this is script that is what you are stuck with. If you used another server - then you could put a scheduling agent in - specify a call back in the request and have the API post to a URL on the client server. – JDBennett Jun 30 '16 at 19:18
  • I have a solution to implement this scenario but I am asking if there is a better solution – mhdbaz Jun 30 '16 at 19:53
  • `I do not want to use asp.net signalr` <--- why? This seems like the round peg that fits the round hole. What reason do you have to not use it? Why try to invent a solution when there is an out of the box solution that has been widely tested readily available? If you can comment on this then maybe there is a way that we (the community) can still provide some insight as to how you can still use it even if the reason is XXX (whatever your reason is). – Igor Jun 30 '16 at 20:10
  • The company does not want to use it. – mhdbaz Jun 30 '16 at 22:21

2 Answers2

0

Use signalR for push notification. Once the data is ready just send a push notification to the client that data is ready.

londondev
  • 231
  • 2
  • 13
0

if you don't wish to use SinglR there is https://pusher.com/ may help you

  • I can not use anything external. I should implement this from zero and i can not use any 3rd party tools or services. – mhdbaz Jul 01 '16 at 15:26
  • OK, let say that you have 4 sources of data, let client browser initiate 4 ajax requests to your server, each request would be for specific datasource(API). and all those requests would update same element(this element could be a JSON element or even an html tag). by doing so you would present data as first come first shows, and you might also make your sorting and other things – Mohammad Al Safra Jul 02 '16 at 00:50
  • I should not send the data from the provider to the client directly. I must process the data then send it to the client and the number of provider is dynamic. to make my question simpler I said I have 3 provider. but in real work our system will run dynamic number of tasks to search the hotel, what we are doing is a system like booking.com – mhdbaz Jul 02 '16 at 07:53
  • does that would help you? http://stackoverflow.com/questions/2927284/need-an-asp-net-mvc-long-running-process-with-user-feedback instead of returning process... you may return data as json and make your works – Mohammad Al Safra Jul 02 '16 at 15:47