如何在appengine上制作倒计时器?

发布于 2024-10-10 21:32:48 字数 145 浏览 0 评论 0原文

我正在开发一个应用程序(在 GAE 上),它需要一个倒计时器,并在计时器达到零时通知客户端。

为了通知客户端,我正在使用 GAE Channel API 。

有什么想法吗? (考虑到 GAE 限制。不使用 Java API 中的线程或计时器)。

I am developing an application (on GAE) that needs a countdown timer and notifies the client side when the timer reaches zero.

To notify the client side i'm using GAE Channel API .

any ideas? (Considering GAE limitations. not using Thread or Timer from Java API).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光无声 2024-10-17 21:32:48

我不知道您需要多少可靠性/精度,无论如何,这里有一些想法:

  1. 使用相应的客户端 ID 将服务器本地时间保存在 memcache 上后,发送“计时器启动” 通过处理该消息的Channel API 向客户端发送消息客户端通过一些 Javascript 计数器。当计时器结束或客户端完成其职责时,调用服务器并执行您的业务逻辑。

  2. 使用 TaskQueue,并在向客户端发送“计时器开始”消息之前,添加具有给定倒计时的任务。 n 秒后添加的任务将被触发,并应向客户端发送“timer-over”消息。

I don't know how much reliability/precision you need, anyway here are a couple of ideas:

  1. After saving the server local time on memcache with the respective client ID, send a "timer-start" message to the client through the Channel API handling it client-side via some Javascript counter. When the timer is over or client has completed its duties , call the server and do your business logic.

  2. Use the countdown parameter of the TaskQueue, and before sending the "timer start" message to the client, add a task with a given countdown. The added task after n seconds will be triggered and should send the "timer-over" message to the client.

甜心小果奶 2024-10-17 21:32:48

不能直接从客户端轮询信息吗?
或者您可以创建每分钟运行一次的 cron 任务并发送适当的消息。

取决于您需要多久执行一次此操作,您需要什么精度

Can't you just poll for the information from client side?
Or you can make cron task that run's once a minute and send appropriate message.

depends on how often do you need to do this, whta prcision you need

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文