如何使用Google App Engine任务队列以(FIFO)顺序执行任务? [英] How to execute tasks in (FIFO) order using Google App Engine Task Queues?
问题描述
我相信Google App Engine中的任务队列(push,pull,deferred)并不能保证任务将以FIFO的顺序执行。例如,假设我有一个任务队列,任务A,B和C,每个任务都有时间戳t_A,t_B和t_C,这样t_A< t_B< T_C。我如何确保按照时间戳顺序执行任务A,B和C?如果任务B失败,我想推迟任务C的执行直到任务B成功执行。我已经看到了一个ETA字段来设置一个任务可以发送的最早时间,但是这看起来更像是一种启发式的,而不是一种保证。
https://github.com/GoogleCloudPlatform/appengine-pipelines
他们已经为您完成了这项工作:
class LogWaitLogInOrder(pipeline.Pipeline):
def run(self,message1,message2,delay):
with pipeline.InOrder():
产生LogMessage(message1)
产量延迟(秒=延迟)
产量LogMessage(消息2)
产量LogMessag e('这会在运行时立即发生')
管道api还为您提供报告/反馈/通知/等。
但是,如果这对您的特殊需求是过度的,那么就像@Paul所建议的那样,只要在第一个任务完成时创建下一个任务,并希望最好的
视频参考:
Google I / O 2010 - 使用Google App Engine的数据流水线:
$ b
https://www.youtube.com/watch?v=zSDC_TU7rtc
I believe task queues (push, pull, deferred) in Google App Engine do not guarantee that tasks will be executed in FIFO order. For example, suppose I have a task queue with tasks A, B, and C, and each task has timestamps t_A, t_B, and t_C, such that t_A < t_B < t_C. How can I ensure that tasks A, B, and C are executed in order of timestamp? If task B fails, I would like to delay the execution of task C until task B executes successfully. I've seen an ETA field to set the earliest time that a task can be sent, but this seems like more of a heuristic, not a guarantee.
Consider using the Pipelines API:
https://github.com/GoogleCloudPlatform/appengine-pipelines
They have already done the work for you:
class LogWaitLogInOrder(pipeline.Pipeline):
def run(self, message1, message2, delay):
with pipeline.InOrder():
yield LogMessage(message1)
yield Delay(seconds=delay)
yield LogMessage(message2)
yield LogMessage('This would happen immediately on run')
The pipelines api also gives you reporting/feedback/notification/etc.
But if that's overkill for your particular needs, then just do as @Paul suggested, just create the next task when the first one completes and hope for the best
video reference:
Google I/O 2010 - Data pipelines with Google App Engine:
https://www.youtube.com/watch?v=zSDC_TU7rtc
这篇关于如何使用Google App Engine任务队列以(FIFO)顺序执行任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!