the following might be not entirely related to the bug, but it seems that the transaction module has support for something along these lines. One can write:
for attempt in transaction.attempts(attempts):
with attempt as txn:
# run application code here, like publish(request)
where the code of Attempt.__exit__ in the transaction module reads:
def __exit__(self, t, v, tb):
if v is None: self.manager.commit()
else:
retry = self.manager._retryable(t, v) self.manager.abort()
return retry
in turn Manager._retryable will simply loop through the data managers and invoke their "should_retry" method, if available, a return True if any of them does:
def _retryable(self, error_type, error):
if issubclass(error_type, TransientError):
return True
for dm in self.get()._resources: should_retry = getattr(dm, 'should_retry', None)
if (should_retry is not None) and should_retry(error): return True
So we could at least make retries very easy when using Storm with the transaction module, by providing a stock should_retry implementation, that could be possibly overridden by application code with some API.
Hi,
the following might be not entirely related to the bug, but it seems that the transaction module has support for something along these lines. One can write:
for attempt in transaction. attempts( attempts) :
with attempt as txn:
# run application code here, like publish(request)
where the code of Attempt.__exit__ in the transaction module reads:
def __exit__(self, t, v, tb):
self. manager. commit( ) _retryable( t, v)
self. manager. abort()
if v is None:
else:
retry = self.manager.
return retry
in turn Manager._retryable will simply loop through the data managers and invoke their "should_retry" method, if available, a return True if any of them does:
def _retryable(self, error_type, error): error_type, TransientError):
if issubclass(
return True
for dm in self.get( )._resources:
should_ retry = getattr(dm, 'should_retry', None) retry(error) :
return True
if (should_retry is not None) and should_
So we could at least make retries very easy when using Storm with the transaction module, by providing a stock should_retry implementation, that could be possibly overridden by application code with some API.