Google App Engine是计划代码执行的最佳方式 [英] Google App Engine, best way to schedule code execution

查看:96
本文介绍了Google App Engine是计划代码执行的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:有些用户可以创建一个文档,并在将来选择日期和时间,以执行该文档上的一些代码。用户也可以取消该预定事件。
我正在寻找GAE中的最佳实施。我正在考虑两种可能的实现方式:

- 为任何文档推送任务,设置eta参数,我可以保存Taskqueue.add(..)的结果在文档中,以防用户想要在执行前删除任务。我不知道是否有最大数量的任务可以启动,并且eta(30)的最大天数可能会成为问题。



- 我可以保存在DataStore日期时间和文档密钥中,并使用cron
每10分钟检查是否有任何条目要处理。我担心这种方法可能很昂贵。因为你的用户可以安排一个事件以及取消 - 我会建议将预定的请求保存到这个应用程序中数据存储并且有一个cron作业检查当时是否有任何计划。



为了减少作业运行的次数,您可以更改日期/用户可以选择作业的时间(例如15分钟增量或每小时)。只要您正确构建预定的请求实体 - 它不应该是数据存储的昂贵命中。为了减少数据存储点击量,您可以在一个查询中获取一系列即将到来的预定事件,并将它们放入memcache中 - 只要您在用户修改缓存时管理该缓存即可。


Problem: some users can create a document, and choose date and time in the future, for the execution of some code on that document. The users can also cancel that scheduled event. I'm looking for the best implementation in GAE. I'm thinking to two possible implementations:

-A push Task for any document, setting the eta parameter, I can save the result of Taskqueue.add(..) in the document, in case the user want to delete the task before its execution. I don't know if there is a max number of tasks that I can launch, and the max number of days for the eta(30) can be a problem.

-I can save in the DataStore datetime and key of the document and use cron to check every 10 mins if there's a any entry to process. I fear that this approach may be expensive. Am i right?

解决方案

Because your users can schedule an event as well as cancel - I would recommend saving the scheduled request to the datastore and have a cron job check if there is anything scheduled at that time.

To reduce the number of times the job runs, you can change the precision of the date/time a user can select for the job (such as 15 minute increments, or hourly). As long as you construct the scheduled request entity properly - it shouldn't be an expensive hit to the datastore. To reduce datastore hits, you can fetch a range of upcoming scheduled events in one query and put them in memcache - as long as you manage that cache when a user modifies one.

这篇关于Google App Engine是计划代码执行的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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