I am creating a webpage to show the listing from my database table,
suppose my database table is updating in every 10 second from my php cron , then i want to sync my backbone model/collection whenever my database table get update from my php cron.
Example:- i have table stock_exchange in which i am storing the stocks rate for various companies, and my cronjob update the stocks rate in every 10 second, To show this on UI i am creating the backbone application but my problem is that whenever my table stock_exchange updated i want to sync my backbone model/collection.
Please help,
Thanks in advance
You can either poll the server by calling stockModel.fetch() every 10 seconds in the browser (via setInterval perhaps), or you can use something like web sockets (via socket.io perhaps) to allow the server to push the latest data to the browser, which you can then do stockModel.set(dataFromServer);. Try something and post some code as stack overflow is intended for specific problems not tutorials.
Related
I am building a UI using React JS, and I want to display in realtime a list of records from a Spring Boot application (let's call it the main app), which is connected to a database that receives the health status of around 500 applications that are being monitored. So each record contains the system IP, app name, date and time of the report, etc.
The solution I can think of right now is to poll the main app every 5 seconds and get the latest records.
But I want to avoid the time-gap of 5 seconds, and instead have a real-time data coming on my UI.
I have seen such systems in action, but I am unable to find a solution to this.
Any pointers/advice/hints/suggestions will be highly appreciated.
For real-time applications, classic HTTP request/response paradigm is not the best option. Take a look at WebSocket protocol and some libraries that can may help you: socket.io (Javascript), Ratchet (PHP)
I'm basic web.api developer. I've almost 10000 records of data. As it is a huge data, basically takes more time to load. So, front end Dev. asked me to give an API such a way that he can pass the size of the records per scroll.
So, my question is Data Loading while scrolling should done by front end developer or web.api developer?. If it is web.api side how can i do that?
Please help me!!!
Thanks in advance.
You need to do it in both client's side and server side. You need to plan your table in the database that it will provide you options for paging so you can retrieve the data by a bulk of data. For example, select * from youTable whrere id between 1 and 50.
in angular, you have to use en event that will be fired every time when you scroll down and call to the web API service. You need to manage the data you already got and the data you will going to get and to send the indexes every time.
nice link in angular - https://sroze.github.io/ngInfiniteScroll/demo_basic.html
Basically front-end developer send a request for data to API with pagination parameter, for example :
for the first time request is like
http://example.com?page=1
here API should return for example first 1-20 data, for the second request the page number is incremented like http://example.com?page=2 so API return 21-40 data and so on.
It may possible front-end developer also pass the number of data required for each request, so you have to send the data in response as request.
I'm facing a challenge on using heroku-connect with Salesforce. I'm inserting a record into a parent object (order) on PG db and I get the PG id when I do the insert, then I have to insert the child (order lines) but heroku-connect hasn't done the insert into Salesforce and I don't have the SFID to be able to insert it.
What would you guys recommend I do? Do I do a requery of the field that tells me if it's synched and refresh the $digest in NG? Or do I do it on the API backend with a interval. I'm a little lost on what route to take.
I'm using streaming API but still can't get the SFID from the callback when I do the insert.
rows: [ { id: 85, sfid: null } ],
EDIT
Got this from Heroku support, works great.
https://devcenter.heroku.com/articles/herokuconnect#relationships-between-objects
We ran into this issue before, when we were evaluating Heroku Connect. We ended up with writing our own sync due several limitations of our data model.
In your case, before saving record into Postgres database, I would suggest to send API REST call to SFDC in order to get SFDC Id - only after that persist a record into Postgres. It will keep data model on SFDC/Postgres side consistent. At the same time API call limit utilization will be relatively low as you will be using API only for record creation.
As you are using Heroku Connect(not stand alone sync app) I would not recommend to put backend scheduler into your web app to control refresh of populated Ids. Logic will be highly coupled and might be painful in future to support you system
I have a C# Web API project on server side and on front-end I have ExtJS 4.2.1 (Javascript framework client).
There is a section in my app where I request to start a long running process (about 5 minutes) and I want to show the user the status of the process being executed.
Basically, the process will run a special calculation for every employee in the database (about 800), so I want to let the user know which Employee is being processed in that moment.
So I was thinking in two ways of doing this, and maybe I don't know if having both is ok.
Use SignalR to show the information of the process in Real Time.
Write to a database table all the process log (every employee that its being processed).
If I use the first approach, if the user close the browser he will loose all the information about the process and if he log into the app again he will only see the actual status.
If I use the second approach, if he log into the app again he could see all the information, and using maybe a timer on client side the data could be refreshed every 5 seconds.
Does anyone have implemented something like this? Any advice is appreciated.
You should use a combination of the two. When you have calculated a employee save the state to the database and publish the change on a service bus.
Let SignalR pick these messages up and forward them to the client. This way the user will see old state when he connects and new state then they arrive with SignalR. I have created a Event aggregator proxy that makes this very easy.
https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy/wiki
Follow the wiki to set it up, here is a demo project
https://github.com/AndersMalmgren/SignalR.EventAggregatorProxy/tree/master/SignalR.EventAggregatorProxy.Demo.MVC4
Live demo
http://malmgrens.org/Signalr/
i have a scenario where i have to load data from SQL server when i start running a web service. Later i have to use this data for my application, instead of accessing it every time from Database. In addition to this this data should be refreshed every one hour without affecting the website operation on the back end.If any of you has came across such scenario please let me know the solution. By the way i am using asp.net web services, SQL server database, and DNN for my front end.Thanks in advance.
In Global Asax,Application start event you can load all your data in the Dataset.
And by using Sql Cache dependency, You can refresh the data for each hour.But loading the
Entire data is not advisable.By making so you memory will be full.There will
be Performance degrade.
http://www.codeproject.com/Articles/14976/ASP-NET-Caching-Dependencies
Pre-loading all of your data is not a good practice because the database loses its purpose then. It’s probably ok for some data that is very rarely updated but needed very frequently but most definitely not for all the data you have in database.
As for the loading of data you can use app start event as others have already suggested.
Regarding caching – use Application object to make this data available to all parts of application and add a proprety to it that will keep the time of the last update. Then just create separate service that will check the last update time every X minutes and refresh the data when the time comes.