setInterval on firebase instead of using cron

断了今生、忘了曾经 提交于 2019-12-24 06:00:25

问题


I am making a spam counter ( on Firebase ). What I do is I use database trigger on firebase cloud functions to increment a path (/counter/${uid}). This path will hold an integer for each user that other path will have a security rule that reference to it and check whether it exceed the limit. However, I would like to clear the counter once a day.

When I search on google I found official way of firebase to do this by using another Google cloud service to deploy cron job. However, I wonder if I use setInterval on cloud function instead would work. This task would only be a one line execution ( admin.database().ref('/counter').set({}) . And it is not so serious that if it were to skip once or twice of the execution due to some problem, it should be ok.

Thanks


回答1:


The use of setInterval won't work, and it's not really ever recommended to do so. You can use setInterval to keep a function alive for some amount of time, but you will be paying for that time even if the function is just waiting. Also you are still subject to the way Cloud Functions will time out your function (default 60 seconds, max 9 minutes by special configuration).




回答2:


Don't use setInterval as you'll be paying for un-used compute time.

Instead see this video on YouTube; https://www.youtube.com/watch?v=CbE2PzvAMxA

They go into detail of how to setup a free-schedule service and setup a HTTP trigger that should achieve the result you're after.



来源:https://stackoverflow.com/questions/45685079/setinterval-on-firebase-instead-of-using-cron

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!