如何使用Firebase云功能pubsub.schedule?

Sss*_*eve 2 firebase google-cloud-functions firebase-cli

如今,Firebase的Cloud Functions的新功能正在按计划运行功能。因此,我尝试测试示例代码。

index.js文件

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

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


Error: Error occurred while parsing your function triggers.

TypeError: functions.pubsub.schedule is not a function
Run Code Online (Sandbox Code Playgroud)

我的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!');
});
Run Code Online (Sandbox Code Playgroud)

Dou*_*son 14

公告的博客文章指出的火力,功能版本模块也需要最小2.3.0。npm install firebase-functions@latest在您的functions文件夹中运行以对其进行更新,然后再次进行构建和部署。