Update session while claiming

Not totally sure if this is necessary, but I feel like it makes more
sense to err on the side of more data correctness, rather than
hypothesizing about performance
This commit is contained in:
richard-dds 2019-09-17 11:06:23 -04:00
parent abeadee3f3
commit c1b87356ce

View File

@ -21,7 +21,7 @@ def claim_for_update(resource, minutes=30):
or_(Model.claimed_until == None, Model.claimed_until < func.now()), or_(Model.claimed_until == None, Model.claimed_until < func.now()),
) )
) )
.update({"claimed_until": claim_until}, synchronize_session=False) .update({"claimed_until": claim_until}, synchronize_session="fetch")
) )
if rows_updated < 1: if rows_updated < 1:
raise ClaimFailedException(resource) raise ClaimFailedException(resource)
@ -33,4 +33,4 @@ def claim_for_update(resource, minutes=30):
finally: finally:
db.session.query(Model).filter(Model.id == resource.id).filter( db.session.query(Model).filter(Model.id == resource.id).filter(
Model.claimed_until != None Model.claimed_until != None
).update({"claimed_until": sql.null()}, synchronize_session=False) ).update({"claimed_until": sql.null()}, synchronize_session="fetch")