Raise an overlimit exception when overlimit/bound
This commit is contained in:
parent
4a02032618
commit
3c5bec6328
@ -111,11 +111,7 @@ class ZookeeperQuotaEngine(engine.QuotaEngine):
|
||||
raise ValueError("Unsupported kind '%s' encountered"
|
||||
" for resource '%s' owned by '%s'"
|
||||
% (kind, resource, for_who))
|
||||
if not processor.process(stored['details'], amount):
|
||||
raise ValueError("Limit reached, '%s' can not"
|
||||
" consume '%s' of '%s'" % (for_who,
|
||||
resource, amount))
|
||||
return stored
|
||||
return processor.process(stored['details'], amount)
|
||||
|
||||
def consume_many(self, for_who, resources, amounts):
|
||||
who_path = paths.join(self.uri.path, for_who)
|
||||
|
@ -16,3 +16,7 @@
|
||||
|
||||
class DelimiterException(Exception):
|
||||
"""Base class for *most* exceptions emitted from this library."""
|
||||
|
||||
|
||||
class OverLimitException(DelimiterException):
|
||||
"""Exception raised when over some limit."""
|
||||
|
@ -14,6 +14,9 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
from delimiter import exceptions
|
||||
|
||||
|
||||
class UpperBoundProcessor(object):
|
||||
"""Processes a limit given some upper bound."""
|
||||
|
||||
@ -34,8 +37,8 @@ class UpperBoundProcessor(object):
|
||||
def process(self, details, amount):
|
||||
consumed = details['consumed']
|
||||
if consumed + amount > details['bound']:
|
||||
return False
|
||||
raise exceptions.OverLimitException
|
||||
else:
|
||||
details = details.copy()
|
||||
details['consumed'] = consumed + amount
|
||||
return True
|
||||
return details
|
||||
|
Loading…
x
Reference in New Issue
Block a user