我在云功能中遇到冷启动时间的典型(根据许多帖子)问题。似乎承诺的解决方案建议仅导入/导出实际执行的函数,如下所示:
https://github.com/firebase/functions-samples/issues/170#issuecomment-323375462
if (!process.env.FUNCTION_NAME || process.env.FUNCTION_NAME === 'sendFollowerNotification') {
exports.sendFollowerNotification = require('./sendFollowerNotification');
}
Run Code Online (Sandbox Code Playgroud)
这是一个 Javascript 示例,但我使用的是打字稿。我尝试了许多变体,虽然进行了一些构建,但最终我总是坚持我的函数没有被导出,并且部署警告我我将删除现有函数。
这是众多尝试之一:
if (!process.env.FUNCTION_NAME || process.env.FUNCTION_NAME === 'generateInviteURL') {
import ('./invite_functions').then ((mod) => { console.log ("mod follows" ); console.log (mod); exports.generateInviteURL = functions.https.onRequest( mod.generateInviteURL ); } )
.catch ((err) => {console.log ("Trying to import/export generateInviteURL ", err);}) ;
}
Run Code Online (Sandbox Code Playgroud)
提到,在部署时会发生什么是我收到有关该函数被删除的警告。
我能够通过以下方式“避免”该消息:
console.log ("Function name: ", process.env.FUNCTION_NAME);
function dummy_generateInviteURL (req, res) { ; }
exports.generateInviteURL = functions.https.onRequest( dummy_generateInviteURL );
if (!process.env.FUNCTION_NAME || process.env.FUNCTION_NAME === 'generateInviteURL') { …Run Code Online (Sandbox Code Playgroud) node.js firebase typescript google-cloud-functions firebase-cli