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

查看:25
本文介绍了是否不可能在后台有一个每 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 博客上撰写的一篇优秀文章,名为 为 Firebase (cron) 安排云函数.

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?

是的,这是可能的.在这种情况下,您应该在 Cloud Functions for 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天全站免登陆