问题描述
或者,如何保证在等待作业已经运行时作业不会开始运行?基本上,我有一堆不同的任务,我需要完成,有时相同的任务将被要求不止一次,但它只需要完成一次*。如何在AWS中实现此功能?我试过SWF,但不能保证活动ID在不同的工作流中是唯一的。我正在查看SQS,但是我没有看到唯一的消息ID的保证,也没有任何方式要求所有的消息ID目前在队列中的列表。
Or rather, how do I guarantee that a job won't start running if an equivalent job is already running? Basically, I have a bunch of different tasks that I need completed, and sometimes the same task will be requested more than once, but it only needs to be completed once*. How do I implement this in AWS? I've tried SWF, but couldn't guarantee that activity id's were unique among disparate workflows. I'm looking at SQS, but I see no guarantees about unique message id's, nor any way to request a list of all message id's currently in the queue.
任何帮助将非常感谢
*,除非它在将来再次呼叫,因为工作可能会随时间而改变,但这不在这里也没有。
*unless it's called again in the future, because the job might change over time, but that's neither here nor there
推荐答案
一个可能的解决方案是使用一个redis服务器(由AWS提供作为一个带有Elasticache的服务)来实现分布式锁。 Redis是单线程的,这使得它是这样的工作的非常好的候选人。有关上的分布式锁定的许多详细信息和实现示例
One possible solution would be to use a redis server (which is provided by AWS as a service with Elasticache) for implementing a distributed lock. Redis is single threaded which makes it a very good candidate for such a job. You have many details and implementation examples of distributed locking on redis website
这篇关于AWS:如何保证作业只运行一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!