Transfer progress status from server to client side

We have a process running on the server side which takes a long time to complete.

We would like to show the progress of this process on the client side, on the webpage.

We can define a server side function that returns a number between 0 and 100 for the progress.

But how can we call this function dynamically from the client side and update the webpage accordingly?

Yes, either by calling a method with a setInterval from the client, or by a custom publication that send a changed msg with the current % every x ms.

For that second option, you should check arunoda’s bulletproof Meteor.

Be careful. Methods and publications have awareness of the connection (the client) they are running on behalf of. If the long-running process is outside of the connection context it’s likely to be global to all users, which may not be what you want. There are ways of dealing with this (I haven’t looked at Bulletproof Meteor, so don’t know if it’s covered there), but it’s not necessarily as straightforward as you may think.

Reading that, I assume they already know how to deal with getting the data from the process and linking it to the user, if need to be.

Instead of having the client request data, you could push it down to the client using just a raw websocket, or you could use the Streamer package that lets you send events over DDP and have the client subscribe to them. So it would look like

Server

let someUniqueProgressIdenfitier = 'abc';

streamer.emit('progress-' + someUniqueProgressIdenfitier, { progress: 0.2 } );

Client

streamer.on('progress-abc', function({ progress }) {
    alert('the progress is now ' + progress * 10 );
});

The package lets you do allow/deny rules as well if you need it. I’ve used Streamer in the ProseMeteor project and really enjoyed it for things where I want to have data pushed to the client without a subscription or database.