代码之家  ›  专栏  ›  技术社区  ›  Alexander Solonik

如何使我的React应用程序在00:00(即新的一天)自动在数据库中创建条目?

  •  1
  • Alexander Solonik  · 技术社区  · 7 年前

    axios.put(`Dates/${ todaysDate.getFullYear() }/${ this.utilMonthInAlpha(todaysDate.getMonth()) }/${ ( todaysDate.getDate() > 9 ) ? todaysDate.getDate() : '0' + todaysDate.getDate() }/.json` , {
            goodHabits : userStoredHabits,
            totalScore : '0'
    });
    

    以上代码在我的 componentDidMount lifecycle钩子,因此每次用户加载应用程序时,都会执行上面的代码,在我的google firebase数据库中,条目如下所示:

    google firebase database

    理想的例子是今天 9th 还有它的周围 7:37 PM

    1 回复  |  直到 7 年前
        1
  •  2
  •   uturnr    7 年前

    在服务器上

    您可以使用云函数来更新数据库,以响应每小时一次的云发布/订阅触发器。

    您可以存储用户的时区,并且仅当小时作业在用户时区的午夜附近运行时,才能从函数执行数据库更新。

    设置cron作业可以使用 functions-cron

    https://github.com/FirebaseExtended/functions-cron

    在应用程序中