in batch/aiml-workloads/src/rediswq.py [0:0]
def lease(self, lease_secs=60, block=True, timeout=None):
"""Begin working on an item the work queue.
Lease the item for lease_secs. After that time, other
workers may consider this client to have crashed or stalled
and pick up the item instead.
If optional args block is true and timeout is None (the default), block
if necessary until an item is available."""
if block:
item = self._db.brpoplpush(
self._main_q_key,
self._processing_q_key,
timeout=timeout
)
else:
item = self._db.rpoplpush(
self._main_q_key,
self._processing_q_key
)
if item:
# Record that we (this session id) are working on a key.
# Expire that note after the lease timeout.
# Note: if we crash at this line of the program, then GC will
# see no lease for this item a later return it to the main queue.
itemkey = self._itemkey(item)
self._db.setex(
self._lease_key_prefix + itemkey,
lease_secs,
self._session
)
return item