Firebase Pub/Sub定时函数云调度器区域异常设为us-central1求助
Firebase定时函数区域配置异常问题
我创建了一个名为scheduledFunction的Firebase Pub/Sub定时函数,已在代码中指定区域为europe-west1,代码如下:
export scheduledFunction = region("europe-west1") .pubsub .schedule("* * * * *") .timeZone("Europe/Berlin") .onRun((context) => { [...] });
同时在firebase.json中也配置了functions的默认区域为europe-west1:
"functions": { "source": "functions", "region": "europe-west1" }
但部署后发现Google Cloud Scheduler中的任务区域被设置为了us-central1,截图如下:
另外,Http函数的区域设置为europe-west1是可以正常生效的,请问这里遗漏了什么配置?
问题原因与解决方案
Firebase的Pub/Sub定时函数在创建关联的Cloud Scheduler任务时,不会自动继承函数的区域配置——Cloud Scheduler任务的区域由关联的Pub/Sub主题区域决定,默认Pub/Sub主题会创建在us-central1,即使函数本身指定了区域,也不会同步到Pub/Sub主题和调度器任务。
需要在代码中显式指定Pub/Sub的区域,才能让Cloud Scheduler任务在对应区域创建,正确代码写法如下:
export scheduledFunction = region("europe-west1") .pubsub .region("europe-west1") // 显式指定Pub/Sub区域 .schedule("* * * * *") .timeZone("Europe/Berlin") .onRun((context) => { [...] });
或者先获取指定区域的Pub/Sub实例再创建调度:
const europePubSub = admin.pubsub({region: "europe-west1"}); export scheduledFunction = region("europe-west1") .pubsub .schedule("* * * * *") .timeZone("Europe/Berlin") .onRun((context) => { // 使用指定区域的Pub/Sub实例操作 [...] });
内容的提问来源于stack exchange,提问作者Leo
相关产品推荐
相关产品推荐

