是否不可能在后台每24小时调用一次代码? [英] Is it not possible to have a code in the background who will be called every 24h?

查看:48
本文介绍了是否不可能在后台每24小时调用一次代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我对用户的积分进行排名.但是,我仅每24小时计算一次我的排名.我的问题是我不知道在不打扰用户的情况下将计算代码放在哪里.

In my application I do a ranking of the points of a user. However, I do the calculation of my ranking just every 24 hours. My problem is that I do not know where I should put the code of the calculation without disturbing the user.

是否不可能在背景"中有一个每24小时就会被调用一次的代码?因为此刻,当第一个用户在24小时之后使用我的应用程序时,将调用计算代码,但是随后用户必须等待几分钟,直到计算结束.我每个用户的数据都保存在Firebase中.

Is it not possible to have a code in the "background" who will be called every 24h? Because at the moment, the code for the calculation is called when the first user uses my app after 24h, but then the user has to wait some minutes until the calculation is over. My data of every user is saved with Firebase.

提前谢谢!

推荐答案

编辑2019年4月22日:

最近,Google Cloud发布了 Cloud Scheduler ,它允许您安排HTTP请求或Cloud Pub /Sub消息传递给您部署的功能.

Recently, Google Cloud released Cloud Scheduler, which allows you to schedule HTTP requests or Cloud Pub/Sub messages to functions that you deploy.

这项新服务在Firebase上也可以很好地工作,为此,我建议您阅读Doug Stevenson在Firebase博客上撰写的出色文章,该文章名为

This new service works also very well with Firebase and for that I recommend you read an excellent article writen by Doug Stevenson on the Firebase blog named Scheduling Cloud Functions for Firebase (cron).

是否不可能在背景"中有一个每24小时就会被调用一次的代码?

Is it not possible to have a code in the "background" who will be called every 24h?

是的,有可能.在这种情况下,您应该在 Firebase的云函数中编写函数,并在任何时候调用它需要.如果您希望每24小时触发一次,请使用以下服务:

Yes, it is possible. In this case, you should write a function in Cloud Functions for Firebase and call it whenever you needed. If you want to be triggred every 24 hours, use the follwing service:

这意味着即使用户关闭了应用程序,也可以执行该特定计算.有关代码示例,请参见以下帖子中的弗兰克·范·普菲伦(Frank van Puffelen)的答案:

This means that you can do that particular calculation even if the user has the app closed. For a code example, please see Frank van Puffelen's answer from the following post:

这篇关于是否不可能在后台每24小时调用一次代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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