Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4828

How to Continously Poll Model and Update UI Using Ember-Concurrency

$
0
0

@LuisAverhoff wrote:

I need some help in figuring out where would be the best place to poll for my model and what is the best way of going about doing this(I’ve been at this for about a week now).

Here is my situation. There are two routes of interest: /queries/:query_id and /queries/:query_id/results/:result_id The first route show you information about a query, its parameters and allows you to execute a query. Each query can take a certain amount of time to finish. How the frontend determines if a query is finished is by reading the response that we get from polling the backend and checking if status === "COMPLETED"

When a query is executed, a bootstrap tab appears and takes you to /queries/:query_id/results/:result_id and each time that query is executed, a new tab appears and takes you a new result route. Each tab will have to deal with polling the backend for the status of that query execution( result_id ). When I switch between tabs, I want to abort polling for the previous result and start polling for the result that we are currently on. I also want the tab to be continuously updated while polling and not wait until the query is finished.

Initially I’ve tried to poll in my router.

import Router from '@ember/router';
import { task } from "ember-concurrency"

export default Router.extend({

 fetchResultTask: task(function*(resultId){
    while(true) {
       yield timeout(1000);
       const result = this.get("store").findRecord("result", resultId)
       if(result.status === "COMPLETED") {
         break;
       }
       else {
          return result // Send this result to result component so it can update whatever part of the ui it needs to update.
       }
    }
  }).drop()

 model(params) {
   return {
      result: this.get("fetchResultTask").perform(params.result_id)
   }
 }
});
{{result-component result=model.result}} <!-- I want result to continously be updated until status is completed--->

The problem with this is that this will poll only once and wont continuously update my result model until it is finished. So maybe I should update in either in the result controller or result component?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4828

Trending Articles