简体   繁体   English

Firebase:Firestore 未更新 Cloud Function 的计划函数中的数据

[英]Firebase : Firestore not updating data in Cloud Function's scheduled function

I have a very weird experience here, my scheduled function will make an update to a document every 12:00 am and it works, however nothing has change on the document.我在这里有一个非常奇怪的经历,我的预定功能将在每 12:00 am 更新文档并且它可以工作,但是文档没有任何变化。

exports.updatePrediksiData = functions.pubsub.schedule('0 0 * * *')
    .timeZone('Asia/Manila') // Users can choose timezone - default is America/Los_Angeles
    .onRun((context) => {

        //This will be run every day at 12:00 AM

        return updatePrediction()
            .catch(error => {
                return db.collection("Issues").doc(new Date().getTime().toString()).set({
                    error: error.message,
                    log: "updatePrediction failed to update prediction data."
                });
            });

    });

function updatePrediction() {

    const dateFormat = require('dateformat');

    dateFormat.i18n = {
        dayNames: [
            'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat',
            'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
        ],
        monthNames: [
            'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',
            'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'
        ],
        timeNames: [
            'a', 'p', 'am', 'pm', 'A', 'P', 'AM', 'PM'
        ]
    };

    var genVal = getPrediksi();

    const currentDate = new Date();

    //Tuesday and Friday is not included
    if (currentDate.getDay() === 2 || currentDate.getDay() === 5)
        genVal = "----";

    return db
        .collection("Prediksi")
        .doc("Togel")
        .set({
            date: dateFormat(new Date().getTime(), "dd mmmm yyyy"),
            value: genVal
        })
        .then(result => {
            console.log("Updating prediction is success.");
            return true;
        }).catch(error => {
            console.error("Failed updating the prediction.", error);
            throw new Error(error);
        });

}

The expected new data of 'value' field will be "----" since its Friday, but nothing has change even the date. 'value' 字段的预期新数据自其周五以来将为“----”,但即使是日期也没有任何变化。

显示成功的截图

Here as you can see it says success.正如你所看到的,它说成功。

问题

But as you can see no changes has been applied, at first I thought it is with Firebase Firestore Rule but functions are with Admin SDK where rules is not being applied.但是正如您所看到的,没有应用任何更改,起初我认为它与 Firebase Firestore 规则有关,但功能与未应用规则的 Admin SDK 一起使用。 What went wrong here?这里出了什么问题? I am using Node js 10 here, and so far this is the first time I have this issue with writing on Firestore while other functions works perfectly fine.我在这里使用 Node js 10,到目前为止,这是我第一次在 Firestore 上编写代码时遇到这个问题,而其他功能运行良好。 Thanks in advance.提前致谢。

I confirmed that this is the issue with Date object, I changed the timezone to my target audience as a fix like this new Date(new Date().toLocaleString("en-US", { timeZone: "Asia/Jakarta" })) .我确认这是Date对象的问题,我将时区更改为目标受众作为修复,例如new Date(new Date().toLocaleString("en-US", { timeZone: "Asia/Jakarta" })) At first I tried to move the function region as I thought that will fix the problem and will move the timezone, well it is not.起初我试图移动功能区域,因为我认为这将解决问题并移动时区,但事实并非如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM