Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
TryLater.multi_handle: Document context manager magic
Browse files Browse the repository at this point in the history
  • Loading branch information
bsimpson63 committed Jun 15, 2016
1 parent 777c655 commit 3c031c8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions r2/r2/models/trylater.py
Expand Up @@ -75,23 +75,24 @@ class TryLater(tdb_cassandra.View):
_write_consistency_level = tdb_cassandra.CL.QUORUM
_compare_with = TIME_UUID_TYPE

@classmethod
def multi_ready(cls, rowkeys, cutoff=None):
if cutoff is None:
cutoff = datetime.datetime.utcnow()
return cls._cf.multiget(rowkeys,
column_finish=cutoff,
column_count=tdb_cassandra.max_column_count)

@classmethod
@contextlib.contextmanager
def multi_handle(cls, rowkeys, cutoff=None):
if cutoff is None:
cutoff = datetime.datetime.utcnow()
ready = cls.multi_ready(rowkeys, cutoff)

ready = cls._cf.multiget(
rowkeys,
column_finish=cutoff,
column_count=tdb_cassandra.max_column_count,
)

# return the rows to the context caller
yield ready

# on context __exit__ cleanup all the ready columns
for system, items in ready.iteritems():
cls._remove(system, items.keys())
cls._cf.remove(system, items.keys())

@classmethod
def search(cls, rowkey, when):
Expand Down

0 comments on commit 3c031c8

Please sign in to comment.