首页 > 解决方案 > Firebase Cloud Function 计划功能未运行

问题描述

我正在尝试我的第一个预定的云功能。为了测试,我尝试每 1 分钟运行一次,稍后会增加。

我已经部署了它,但还没有看到它通过 Firebase 日志运行。

这是我部署的内容:

const fetchMovies = require('./data/fetchMovies');
exports.fetchMovies = functions.pubsub.schedule('every 1 minute').onRun((context) => {
  console.log("Running, with this context:", context)
  fetchMovies.handler(db);
});

知道这里可能有什么不正确吗?

标签: firebasegoogle-cloud-functions

解决方案


从文档

一个5分钟的例子...

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

Google Cloud Scheduler 支持 Unix Crontab 和 AppEngine 语法。

exports.scheduledFunctionCrontab = functions.pubsub.schedule('5 11 * * *')
  .timeZone('America/New_York') // Users can choose timezone - default is America/Los_Angeles
  .onRun((context) => {
  console.log('This will be run every day at 11:05 AM Eastern!');
  return null;
});

推荐阅读