警告错误:当服务器上的呼叫方法时,流星码必须始终在光纤内运行 [英] WARNING Error: Meteor code must always run within a Fiber when call method on server

查看:153
本文介绍了警告错误:当服务器上的呼叫方法时,流星码必须始终在光纤内运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将流星应用程序部署到服务器上,但是在我的流星服务器日志中总是出现这个错误。

I'm trying to deploy my meteor app onto the server but it always has this error on my meteor server log

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)

但是我已经把它包裹在了Fiber它在本地工作。我真的不知道可能是什么问题。感谢任何人可以帮助。

but I have already wrapped it within Fiber and it works well locally. I really do not know what could be the problem. Appreciate if anyone can help.

// server.js

//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();
});

PS:我已经替换了我的OAuth键。感谢提前

PS:I've replace my OAuth key. Thanks in advance

推荐答案

我想你应该用 Meteor.bindEnvironment 而不是直接使用纤维 - 参见这里 https://gist.github.com/possibilities/3443021

i think you should wrap your callbacks with Meteor.bindEnvironment rather than use fibers directly - see here https://gist.github.com/possibilities/3443021

我很广泛地使用它,它的效果很好,因为你留在光纤中而不是离开而不必重新输入

i use this quite extensively and it works well because you stay within the fiber rather than leaving and having to re-enter

正常回调风格

someMethod({OPTIONS}, function(callbackReturnArgs){
    //this is the normal callback
));

绑定环境包裹回调

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

如果您一直打包这样的异步回调,流星总是可以访问

if you consistently wrap async callbacks like this, meteor is always accessbile

此处

Fiber(function(){
  Meteor.call('streamTwit', twit);
}).run();

你不需要光纤包裹这个,你已经在 Meteor .startup 上下文,所以这是多余的 - 只是 Meteor.call(...); 会做的伎俩

you do not need to fiber wrap this, you are already in the Meteor.startup context, so this is redundant - just the Meteor.call(...); will do the trick

这篇关于警告错误:当服务器上的呼叫方法时,流星码必须始终在光纤内运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆