1
我设置了多个触发器,如:为什么Google Cloud Function在部署后多次运行全局功能?
exports.doSomething = functions.firestore.document('col/{doc}').onCreate(event => {})
比我有我想要运行时刻,当我部署一个功能。这看起来是这样的:
now()
function now(){
console.log("running function")
}
而且我得到这个在我的日志:
它为什么跑这么多次,并得到其他函数调用?
的完整代码,只是测试它和运行函数被调用4次,相同数量的触发我已设置:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const db = admin.firestore()
var geoip = require('geoip-lite');
exports.z = functions.firestore.document('converasdassdtIP/{UID}').onCreate(event => { })
exports.x = functions.firestore.document('sads/{UID}').onCreate(event => { })
exports.n = functions.firestore.document('asdasasdsa/{UID}').onCreate(event => { })
exports.m = functions.firestore.document('converasdasddtIP/{UID}').onCreate(event => { })
now()
function now(){
console.log("running function")
}
你的代码在哪里调用'now()'?你可以添加你的一些'function/index.js'到这个问题吗? – Callam
@Callam看到我的编辑 –
每次触发函数时,都会调用'now()'的调用,因为它位于'index.js'文件的根范围内,因此每个运行的云功能都会看到登录。你想用这个日志实现什么?你想什么时候打印? – Callam