Kill a method/ddp message before it finishes?


#1

Hi folks, is there any way to kill a method while it is running? May I grab a ddp message/fiber by its connection id and then stop it?

I have a method on the server that does some time-consuming (often more than 10 seconds) fetching of hundreds of thousands of data. This method is called rather frequently (with different parameters).

Because I only need the result from the most recent call of this method, I want to kill the method whenever it is being called again. This would save enormous time. Is it possible to achieve this?

p.s. I’m using this.unblock() inside the method.

Thanks!


#2

I don’t have the answer to your specific question, but i guess it’s not a good idea for the server to execute a 10 seconds plus task, since during those 10 seconds the server can’t do anything else.
Either you find a way to cut your task in small increments that can be put in a queue (and then your “last task priority” can be solved by other means), or you should take a look at some multithread/multiprocesses solutions for node.
IMHO


#3

This is built into the ddp or there is no such package I know.
So, it is just your method is running and getting no response.

If this method is some random task, that’s okay.
If that’s not, getting data into Meteor is CPU intensive. You may be need to MongoDB aggregation pipelines.


#4

After using the MongoDB aggregation pipelines the performance improved significantly. Thanks!