【问题标题】:Meteor: How to call a server method which is independent of client and call it at regular interval?Meteor:如何调用独立于客户端的服务器方法并定期调用它?
【发布时间】:2016-02-15 22:35:56
【问题描述】:

我有一个方法只需要在服务器中运行(独立于客户端),我想定期运行该方法。此方法调用 2 个 api 并将数据插入到数据库中。有人可以澄清以下疑问吗?

  1. 我必须在 Meteor.method 中编写我的方法吗?

    Meteor.Method({ myMethod: function() {.....} });

  2. 我必须在 Meteor.method 中使用 setInterval 吗?

  3. 我必须在 Meteor.startup 中编写我的代码吗?

  4. 1234563 /p>
  5. 如何在流星中实现 upsert?它是一个非常简单的用户,我需要查看数据库中是否已经存在用户名。如果不是,则插入,否则更新。

【问题讨论】:

    标签: meteor


    【解决方案1】:
    1. 是的,这样写方法。

    2. 你可以像这样调用服务器内部的方法:

      Meteor.setInterval(function() { Meteor.call('yourMethod', arg1, arg2 }, 5000)

    此代码应该在 /server 文件夹中或包装到

    `if (Meteor.isServer) {
    
    }`
    

    应该这样做。

    1. 从区间开始看看?

    2. 您可以在此处阅读有关 upsert 的信息 http://docs.meteor.com/#/full/upsert

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多