我如何才能访问 GAE 上的任务列表?
我计划使用 GAE 的 TaskQueue API 来刷新 HTML 页面的缓存,我将其保存在数据存储区(和内存缓存,但数据存储区更可靠)中。
每周一次,我添加/编辑一些数据,并且需要重新生成关联的 HTML 页面,触发任务就是这样做的方法。
请注意,不同的编辑可能意味着更改相同的缓存页面。例如,主页包含来自不同数据的多个部分的片段。我想要的是以延迟(例如,使用一小时的倒计时)将任务启动到任务队列,以便我可以积累多次编辑,最后,缓存的页面将重新生成只有一次。
问题是,如果一小时内已经有一个任务排队重新生成页面 X,我不需要添加任务来重新生成页面 X。因此,我需要检查任务列表,看看是否已经有一个。
如何访问任务列表?
I'm planning on using GAE's TaskQueue API to refresh my cache of HTML pages, which I save in the Datastore (and memcache, but Datastore is more reliable).
Once a week, i add/edit some data, and need to regenerate associated HTML pages, and triggering tasks is the way to do.
Note that different edits may imply changing the same cached page. For instance, the homepage has snippets from several parts from different data. What I want is to launch tasks to the task queue with a delay (using countdown of an hour, for example) so that I can accumulate several edits, and in the end, the cached pages will be regenerated only once.
The problem is, I don't need to add a task to regenerate page X if there is already a task queued to regenerate page X in a hour. Thus, I need to check the task list and see if there is already one.
How can I access the task list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我看到添加相同的任务会引发 DuplicateTaskNameError,也许这就是我所需要的。
I saw that adding the same Task will raise a DuplicateTaskNameError, maybe that´s all I need.
每当您进行编辑时,您只需从缓存中删除该项目即可。然后,当有人读取某个页面时,您会注意到该页面不在缓存中,然后从数据存储中获取该页面,并使用新检索的数据更新缓存。无论如何,您应该已经有了这种逻辑,因为您不能总是保证该项目将在缓存中。这将影响更新后第一次获取的速度,但之后就没有问题了。
Whenever you make an edit you could simply remove the item from the cache. Then when someone comes to read a page you would notice that its not in the cache and fetch it from the datastore at that point and update the cache with the newly retrived data. You should already have this kind of logic anyway since you can't always guarantee the item will be in cache. This will impact the speed of the first fetch after you make the updates but after that it will be fine.