在Firebase上使用setInterval而不是使用cron [英] setInterval on firebase instead of using cron

查看:79
本文介绍了在Firebase上使用setInterval而不是使用cron的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个垃圾邮件计数器(在Firebase上).我要做的是在Firebase云函数上使用数据库触发器来增加路径(/counter/$ {uid}).该路径将为每个用户保留一个整数,而其他路径将具有引用该整数的安全规则,并检查该规则是否超出限制.但是,我想每天清理一次柜台.

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.

当我在Google上搜索时,我发现了使用其他Google云服务来部署cron作业的正式的Firebase方式.但是,我想知道我是否可以在云函数上使用setInterval而不起作用.此任务只能是一行执行(admin.database().ref('/counter').set({}).由于它由于以下原因而跳过了一次或两次执行,因此并不那么严重:有些问题,应该没事.

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.

谢谢

推荐答案

setInterval的使用不起作用,因此也从未真正建议这样做.您可以使用setInterval使某个功能保持活动状态一段时间,但是即使该功能只是在等待,您仍要为此付出代价.另外,您仍然受Cloud Functions超时的约束(默认情况下为60秒,通过特殊配置最多9分钟).

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).

这篇关于在Firebase上使用setInterval而不是使用cron的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆