使用 TaskQueue 和 Datastore 找出一组任务完成时间 [英] Figure out group of tasks completion time using TaskQueue and Datastore

查看:22
本文介绍了使用 TaskQueue 和 Datastore 找出一组任务完成时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个推送任务队列,我的每个作业都包含多个类似的 TaskQueue 任务.这些任务中的每一个都需要不到一秒钟的时间来完成,并且可以将新任务添加到队列中(它们也应该完成以认为作业已完成).任务结果写入数据存储.

I have a push task queue and each of my jobs consists of multiple similar TaskQueue tasks. Each of these tasks takes less than a second to finish and can add new tasks to the queue (they should be also completed to consider the job finished). Task results are written to a DataStore.

目标是了解工作何时完成,即所有任务都已完成.

The goal is to understand when a job has finished, i.e. all of its tasks are completed.

写入非常频繁,我无法将结果存储在一个实体组中.有什么好的解决方法吗?

Writes are really frequent and I can't store the results inside one entity group. Is there a good workaround for this?

推荐答案

在类似的上下文中,我使用了一个基于 memcache 的方案,它没有像数据存储实体组那样有明显的写入速率限制:

In a similar context I used a scheme based on memcache, which doesn't have a significant write rate limitation as datastore entity groups:

  • 每个作业都有一个唯一的内存缓存键与之关联,它将传递给它可能入队的每个后续执行任务
  • 每个执行任务都使用当前时间戳更新与作业键对应的内存缓存值,并将完成检查任务排入队列,延迟一个空闲超时值,大到足以声明作业已完成.
  • 每个完成检查任务都会将作业键对应的内存缓存值与当前时间戳进行比较:
    • 如果 delta 小于空闲超时,则表示作业未完成(由于此完成检查任务已入队,因此执行了其他一些任务,因此其他一些完成检查任务在队列中)
    • 否则作业就完成了

    注意:空闲超时应该大于任务可能在队列中花费的最长时间.

    Note: the idle timeout should be larger than the maximum time a task might spend in the queue.

    这篇关于使用 TaskQueue 和 Datastore 找出一组任务完成时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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