celery/kombu — pull request #431 by cce (2014-11-19 16:06:51+00:00)
Title: SQS: Set delivery tag to SQS message receipt handle

This addresses #137 and reports like [this Stack Overflow question](http://stackoverflow.com/questions/17262958/celery-with-sqs-errors-in-logs). I received similar errors occasionally while using the SQS backend.

My understanding of the reason for this problem is because SQS messages may be delivered twice, especially if you are polling frequently. So that means the same delivery_tag UUID could be delivered to the same client in separate `boto.sqs.message.Message` instances. This results in the backtrace reported occasionally when acking the same delivery_tag twice (depending on whether the `_flush()` occurs between acks?), raising a KeyError the second time. This actually leaves the unacked duplicate message on the SQS queue until the visibility timeout expires, and a future worker tries to ack it again later.

To distinguish between duplicate messages the SQS API requires you use an SQS message's "receipt handle" to delete a message. From [their docs](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/ImportantIdentifiers.html):
> If you receive a message more than once, each time you receive it, you get a different receipt handle. You must provide the most recently received receipt handle when you request to delete the message or the message might not be deleted.

So this change uses the receipt handle as the delivery_tag, leaving idempotency of tasks when duplicates are received up to the user. I'm not sure if the delivery_tag is required to be the request UUID, so let me know if this is actually a bad idea. However it seems to be working for me in my testing and I am able to ack all messages even when duplciates are received without this exception.