in aws_xray_sdk/core/sampling/reservoir.py [0:0]
def _borrow_or_take(self, now, can_borrow):
self._adjust_this_sec(now)
# Don't borrow if the quota is available and fresh.
if (self._quota is not None and self._quota >= 0 and
self._TTL is not None and self._TTL >= now):
if(self._taken_this_sec >= self._quota):
return ReservoirDecision.NO
self._taken_this_sec = self._taken_this_sec + 1
return ReservoirDecision.TAKE
# Otherwise try to borrow if the quota is not present or expired.
if can_borrow:
if self._borrowed_this_sec >= 1:
return ReservoirDecision.NO
self._borrowed_this_sec = self._borrowed_this_sec + 1
return ReservoirDecision.BORROW