Progress Indicator in Playback Structure

What is the best way to implement some kind of progress indicator on Play?

I have a simple import page where the user can download the csv file. The server then performs some length processing until the import is complete. I would like to redirect the user to a separate page after loading and give him some constant feedback on this page. "150 of 856 datasets imported."

The load action launches a controller method that can launch a laborious task in its thread, but how do I get the status of a job using an ajax call from another page (since the game does not have any state between requests)?

+5
source share
2 answers

What you are likely to do is create a task from your controller. In fact, if you are reading the Play documentation, you are strongly advised to do lengthy processing in Jobs so that they do not hang HTTP request streams.

So, your work is done by processing the CSV file. The next step is to record when each data set has been processed. So, suppose you pass your task a link, for example, uid or some unique number that you pass to your client. Then you just need to write (possibly to the database, if you want to easily match statelessness and scale) each increase in your number of data sets processed against your unique identifier.

eg

@Entity
public class DatasetProgress extends Model {

    public Long uid;
    public Long datasetsDone;
    public Long datasetsTotal;

}

, DatasetProgress uid, .

+3

, , - . . , , .

- - ( ).

+1

All Articles