javascript - Firebase 函数 - 间隔内的间隔,以减少调用
问题描述
调用量越大,使用 Firebase 云函数的成本也越高。
我想知道这是否意味着当我在一个函数中调用/运行一个函数 x 次时我可以降低成本。我已经对此进行了测试,结果发现调用减少了。这就是我的意思:
exports.functionName = functions.region("europe-west2").pubsub.schedule('every 1 minutes')
.onRun((context) => { //counts as invocation
console.log("Running...")
var timesRun = 0;
var interval = setInterval(() => {
timesRun += 1;
if(timesRun === 6){
console.log("Stopping interval...")
clearInterval(interval);
}
console.log("Executing...")
//code... for example fetching json
}, 10000); //doesn't count as invocation
});
有了这个,我可以每分钟运行我的代码 5 次,而官方调用等于 1。这真的更有效,还是我错过了什么?
解决方案
推荐阅读
- reactjs - 将 Reactjs + NodeJs 应用程序部署到 Window Machine (AWS)
- ssl - 如何使用我拥有的有效 SSL 证书在 https 中为 pm2 服务器提供反应应用程序?
- vue.js - vuetify中如何扩大v-switch的可点击区域
- javascript - React 功能组件不渲染但用于
- r - 如何使用 R 中的 which.min 函数返回元素的名称
- python - Python 中的异步 HTTP POST 请求
- spring-boot - 将 Axon Framework 与 Spring Boot 一起使用时出现 AXONIQ-4002 错误
- java - 当 minifyEnabled 设置为 true 时,Rxjava3 无法按预期工作
- mule - 从源代码构建 Mule 运行时引擎
- mysql - 使用选择总和计算每天的所有交易