-
-
Save anonymous/0f801780f2f43cdbb9b2 to your computer and use it in GitHub Desktop.
create with find and modify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create(self, name, project=None): | |
# NOTE(flaper87): If the connection fails after it was called | |
# and we retry to insert the queue, we could end up returning | |
# `False` because of the `DuplicatedKeyError` although the | |
# queue was indeed created by this API call. | |
# | |
# TODO(kgriffs): Commented out `retries_on_autoreconnect` for | |
# now due to the above issue, since creating a queue is less | |
# important to make super HA. | |
try: | |
# NOTE(kgriffs): Start counting at 1, and assume the first | |
# message ever posted will succeed and set t to a UNIX | |
# "modified at" timestamp. | |
counter = {'v': 1, 't': 0} | |
scoped_name = utils.scope_queue_name(name, project) | |
self._collection.find_and_modify({'p_q': scoped_name}, | |
{'$setOnInsert':{'p_q': scoped_name, 'm': {}, | |
'c': counter}}, upsert=True) | |
except pymongo.errors.DuplicateKeyError: | |
return False | |
else: | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment