0

我在 Meteor 中有一个方法需要一些时间来执行,并且这个方法被调用了很多次,参数不同。

但是客户端可以在数据仍在加载时更改参数,所以我希望服务器能够以某种方式清除方法队列。那可能吗

因此,仅举个例子:

服务器:

Meteor.methods({
  'getLongTimeExecutedData': function (settings, reset) {
    let self = this;
    if(reset) {
      // How to reset my entire queue here.
    }
    Meteor._sleepForMs(1000);
    let myData = { settings: settings, timestamp: new Date() };
    return myData;
  }
});

客户:

Meteor.call('getLongTimeExecutedData', { param1: 'test' , param2: 1 }, false);
Meteor.call('getLongTimeExecutedData', { param1: 'test' , param2: 2 }, false);
Meteor.call('getLongTimeExecutedData', { param1: 'test' , param2: 3 }, false);
...
// Reset queue on server with true here
Meteor.call('getLongTimeExecutedData', { param1: 'test2' , param2: 1 }, true);
Meteor.call('getLongTimeExecutedData', { param1: 'test2' , param2: 2 }, false);
Meteor.call('getLongTimeExecutedData', { param1: 'test2' , param2: 3 }, false);
...

我不想使用 this.unblock(),因为该方法使用的是 MS SQL 连接,如果它仍然执行,它会占用大量对服务器的不需要的请求。

希望有人有一些想法?:)

// 彼得

4

1 回答 1

0

有几个可用的作业队列项目

https://github.com/artwells/meteor-queue

https://github.com/vsivsi/meteor-job-collection

于 2016-03-01T00:22:33.977 回答