Skip to content

Instantly share code, notes, and snippets.

@svetlyak40wt
Created December 13, 2012 14:15
Show Gist options
  • Save svetlyak40wt/4276635 to your computer and use it in GitHub Desktop.
Save svetlyak40wt/4276635 to your computer and use it in GitHub Desktop.
Mongo lock
now = datetime.utcnow()
then = now + timedelta(seconds=LOCK_TIME)
if db.locks.find_and_modify({'type': command, 'time': {'$lt': now}},
{'type': command, 'time': then},
new=True,
upsert=(not bool(mongo.dbtaxi.locks.find({'type': command}).count()))):
do_stuff()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment