警告错误:在服务器上调用方法时,Meteor代码必须始终在光纤内运行

You*_*Tan 4 deployment mongodb meteor

我正在尝试将我的meteor应用程序部署到服务器上,但它在我的meteor服务器日志上总是有这个错误

Fri Jun 21 2013 11:39:31 GMT+0000 (UTC)] INFO HIT /img/bg.png
183.90.41.21 [Fri Jun 21 2013 11:39:32 GMT+0000 (UTC)] INFO HIT /favicon.ico 183.90.41.21 [Fri Jun 21 2013 11:39:41 GMT+0000 (UTC)] INFO HIT /form 183.90.41.21 [Fri Jun 21 2013 11:39:42 GMT+0000 (UTC)] INFO HIT /favicon.ico 183.90.41.21 [Fri Jun 21 2013 11:39:49 GMT+0000 (UTC)] WARNING           }).run();
             ^ [Fri Jun 21 2013 11:39:49 GMT+0000 (UTC)] WARNING app/server/server.js:53 [Fri Jun 21 2013 11:39:49 GMT+0000 (UTC)] WARNING Error: Meteor code must always run within a Fiber
    at _.extend.get (app/packages/meteor/dynamics_nodejs.js:14:13)
    at _.extend.apply (app/packages/livedata/livedata_server.js:1268:57)
    at _.extend.call (app/packages/livedata/livedata_server.js:1229:17)
    at Meteor.startup.Meteor.methods.streamTwit (app/server/server.js:51:22)
Run Code Online (Sandbox Code Playgroud)

但是我已经将它包裹在Fiber中并且它在本地运行良好.我真的不知道会出现什么问题.感谢是否有人可以提供帮助.

//server.js

Meteor.startup(function () {
    var require = Npm.require;
    var fs = require('fs');
    var path = require('path');
    var base = path.resolve('.');
    var isBundle = fs.existsSync(base + '/bundle');
    var modulePath = base + (isBundle ? '/bundle/static' : '/public') + '/node_modules';

    var ntwitter = require(modulePath + '/ntwitter');
    var Fiber = require(modulePath + '/fibers');

    var twit = new ntwitter({
      consumer_key: 'my key',
      consumer_secret: 'my key',
      access_token_key: 'my key',
      access_token_secret: 'my key'
    });

  Meteor.methods({
      postText : function(questionText){
        twit.verifyCredentials(function (err, data) {
        if (err) {
          console.log("Error verifying credentials: " + err);
          process.exit(1);
        }
      }).updateStatus(questionText,
        function (err, data) {
          if (err) {
            console.log('Tweeting failed: ' + err);
            return false;
          }
          else {
            console.log('Success!');
            return true;
          }
        }
      );
    },

    streamTwit: function (twit){
      var userid = '1527228696';
    twit.stream(
    'statuses/filter',
    { follow: userid},
      function(stream) {
          stream.on('data', function(tweet) {

          Fiber(function(){
            if(tweet.user.id_str === userid)
            {
              Meteor.call('addQn', tweet);
            }
          }).run();
          console.log('----------------------tracking tweet-----------------');
              console.log(tweet);
              console.log('---------------------------------------------------------');
              console.log(tweet.user.screen_name);
              console.log(tweet.user.name);
              console.log(tweet.text);
          });
        }
      );
    },

    addQn:function(tweet){
      questionDB.insert({'tweet': tweet, 'date': new Date()});
    }
  });
Fiber(function(){
  Meteor.call('streamTwit', twit);
}).run();
});
Run Code Online (Sandbox Code Playgroud)

PS:我已经替换了我的OAuth密钥.提前致谢

nat*_*ser 9

我认为你应该用你的回调包装Meteor.bindEnvironment而不是直接使用光纤 - 请看这里https://gist.github.com/possibilities/3443021

我使用它非常广泛,它运作良好,因为你留在光纤而不是离开,不得不重新进入

正常的回调风格

someMethod({OPTIONS}, function(callbackReturnArgs){
    //this is the normal callback
));
Run Code Online (Sandbox Code Playgroud)

绑定环境包装回调

someMethod({OPTIONS}, Meteor.bindEnvironment(
  function(callbackReturnArgs){
    //this is the normal callback
  },
  function(e){
    console.log('bind failure');
  }
));
Run Code Online (Sandbox Code Playgroud)

如果你一直包装像这样的异步回调,那么meteor总是可以访问


这一点在这里

Fiber(function(){
  Meteor.call('streamTwit', twit);
}).run();
Run Code Online (Sandbox Code Playgroud)

你不需要纤维包装,你已经在Meteor.startup上下文中,所以这是多余的 - 只是Meteor.call(...);意志就行了