Correct purge call, add missing lock module
This commit is contained in:
parent
387014f77b
commit
32e1bc6aa5
@ -90,18 +90,18 @@ class ChaindFsAdapter(ChaindAdapter):
|
||||
def succeed(self, block, tx):
|
||||
if self.store.is_reserved(tx.hash):
|
||||
raise QueueLockError(tx.hash)
|
||||
|
||||
r = self.store.final(tx.hash, block, tx, error=False)
|
||||
self.store.purge(tx.hash)
|
||||
(k, v) = self.store.get(tx.hash)
|
||||
self.store.purge(k)
|
||||
return r
|
||||
|
||||
|
||||
def fail(self, block, tx):
|
||||
if self.store.is_reserved(tx.hash):
|
||||
raise QueueLockError(tx.hash)
|
||||
|
||||
r = self.store.final(tx.hash, block, tx, error=True)
|
||||
self.store.purge(tx.hash)
|
||||
(k, v) = self.store.get(tx.hash)
|
||||
self.store.purge(k)
|
||||
return r
|
||||
|
||||
|
||||
|
34
chaind/lock.py
Normal file
34
chaind/lock.py
Normal file
@ -0,0 +1,34 @@
|
||||
# standard imports
|
||||
import time
|
||||
|
||||
# local imports
|
||||
from .error import BackendError
|
||||
|
||||
BASE_DELAY = 0.01
|
||||
BASE_DELAY_LIMIT = 3.0
|
||||
|
||||
|
||||
class StoreLock:
|
||||
|
||||
def __init__(self, delay=BASE_DELAY, delay_limit=BASE_DELAY_LIMIT, error=BackendError, description=None):
|
||||
self.base_delay = delay
|
||||
self.delay = delay
|
||||
self.delay_limit = delay_limit
|
||||
self.error = error
|
||||
self.description = description
|
||||
|
||||
|
||||
def again(self, e=None):
|
||||
if self.delay > self.delay_limit:
|
||||
err = None
|
||||
if e != None:
|
||||
err = str(e)
|
||||
else:
|
||||
err = self.description
|
||||
raise self.error(err)
|
||||
time.sleep(self.delay)
|
||||
self.delay *= 2
|
||||
|
||||
|
||||
def reset(self):
|
||||
self.delay = self.base_delay
|
Loading…
Reference in New Issue
Block a user