【问题标题】:how to use firebase cloud function pubsub.schedule?如何使用firebase云功能pubsub.schedule?
【发布时间】:2019-09-09 10:52:17
【问题描述】:

今天,Cloud Functions for Firebase 有一个新功能,可以按计划运行功能。所以我尝试测试示例代码。

index.js 文件

exports.scheduledFunction = functions.pubsub.schedule(‘every 5 minutes’).onRun((context) => {
  console.log(‘This will be run every 5 minutes!’);
});

但是当我尝试部署它时,我收到以下错误消息:


Error: Error occurred while parsing your function triggers.

TypeError: functions.pubsub.schedule is not a function

我的 firebase 工具版本是 6.7(今天更新)

解决办法是什么?

我在这里检查了示例 git 代码 (https://github.com/firebase/functions-samples/blob/master/delete-unused-accounts-cron/functions/index.js)

但它也会导致同样的错误:

functions.pubsub.schedule 不是函数

谁能帮我解决这个问题?

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) => {
   console.log('This will be run every 5 minutes!');
});

【问题讨论】:

    标签: firebase google-cloud-functions firebase-cli


    【解决方案1】:

    announcement blog post 指出 firebase-functions 模块的版本也需要至少为 2.3.0。在您的函数文件夹中运行 npm install firebase-functions@latest 以更新它,然后再次构建和部署。

    【讨论】:

    • 这个解决了我的问题。如果它也解决了您的问题@SssSteve,这应该是公认的答案。
    • 这对我有用。安装在函数根文件夹中。
    • 我收到此错误函数[scheduledFunction]:函数被忽略,因为 pubsub.googleapis.com 模拟器不存在或未运行。
    • 我正在使用 "firebase-functions": "^3.3.0" ,但我仍然遇到这个问题
    【解决方案2】:

    这是https://firebase.google.com/docs/functions/schedule-functions的文档

    export const scheduledFunction = functions.pubsub.schedule('every 5 minutes')
    .timeZone('Asia/Jakarta')
    .onRun((context) => {
        console.log('This will be run every 5 minutes!');
    });
    

    您可以将时区设置为附加

    【讨论】:

    • 完全不相关
    【解决方案3】:

    我遇到了同样的问题。

    我必须将我的firebase-tools 更新到版本^6.7.2。 我还更新了firebase-functions,但仅此一项并没有完成这项工作。所以我会更新所有的 firebase 依赖项(firebase-tools/admin/functions)。

    【讨论】:

      猜你喜欢
      • 2019-10-09
      • 2017-10-28
      • 1970-01-01
      • 2020-06-09
      • 2019-04-16
      • 2018-04-30
      • 1970-01-01
      • 1970-01-01
      • 2019-04-05
      相关资源
      最近更新 更多