[英]firebase function error deploying a scheduled function listener
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
var database = admin.database();
//var tarih = new Date();
var d = Date.now();
var userTimeZoneOffset = 3;
var timeInRegion = new Date(d + (userTimeZoneOffset*60*60*1000));
exports.scheduledFunctionCrontab = functions.pubsub.schedule('5 11 * * *')
.timeZone('Turkey/Istanbul').onRun(async (context) => {
var snapshot = await database.ref('Kullanicilar/{userId}/sistemdurumu').get();
var oldDeger = snapshot.before.val();
var newDeger = snapshot.after.val();
if (newDeger > oldDeger){
database.ref(`Kullanicilar/${Context.params.userId}/sistemdurumu1`).await().set(timeInRegion.getFullYear());
database.ref(`Kullanicilar/${Context.params.userId}/sistemdurumu2`).await().set(timeInRegion.getMonth()+1);
database.ref(`Kullanicilar/${Context.params.userId}/sistemdurumu3`).await().set(timeInRegion.getDate());
}
return null;
});
我得到部署的錯誤。 你能幫我解決這個問題嗎?
我部署功能
功能: 完成運行預部署腳本。 i 功能:確保啟用所需的 API cloudfunctions.googleapis.com... i 功能:確保啟用所需的 API cloudbuild.googleapis.com... 功能:啟用所需的 API cloudbuild.googleapis.com 功能:所需的 API cloudfunctions.googleapis .com 已啟用 i 功能:准備用於上傳的功能目錄... i 功能:用於上傳的打包功能 (69.93 KB) i pubsub:確保啟用所需的 API pubsub.googleapis.com... i 調度程序:確保所需的 API 雲調度程序。 googleapis.com 已啟用...調度程序:所需的 API cloudcheduler.googleapis.com 已啟用 pubsub:所需的 API pubsub.googleapis.com 已啟用功能:功能文件夾上傳成功 i 功能:更新 Node.js 14 功能 scheduleFunctionCrontab(us-central1 )... 函數[scheduledFunctionCrontab(us-central1)]:更新操作成功。 i 函數:清理構建文件...函數部署有以下函數錯誤:scheduledFunctionCrontab(us-central1)
要嘗試重新部署這些功能,請運行: firebase deploy --only "functions:scheduledFunctionCrontab"
要繼續部署其他功能(例如數據庫),請運行:firebase deploy --except functions
錯誤:函數未正確部署。
如 文檔中所述,
timeZone 的值必須是tz 數據庫中的時區名稱。
因此時區應該是Asia/Istanbul
而不是Turkey/Istanbul
。
除此之外,數據庫更新操作返回一個承諾,所以你應該使用await
。 如果需要,您可以在Promise.all()
同時運行它們。
exports.scheduledFunctionCrontab = functions.pubsub.schedule('5 11 * * *')
.timeZone('Asia/Istanbul').onRun(async (context) => {
^^^^
var snapshot = await database.ref('Kullanicilar/{userId}/sistemdurumu').get();
var oldDeger = snapshot.before.val();
var newDeger = snapshot.after.val();
if (newDeger > oldDeger){
await database.ref(`Kullanicilar/${Context.params.userId}/sistemdurumu1`).set(timeInRegion.getFullYear());
await database.ref(`Kullanicilar/${Context.params.userId}/sistemdurumu2`).set(timeInRegion.getMonth()+1);
await database.ref(`Kullanicilar/${Context.params.userId}/sistemdurumu3`).set(timeInRegion.getDate());
}
return null;
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.