Correct purge call, add missing lock module

This commit is contained in:
lash 2022-05-02 20:10:30 +00:00
parent 387014f77b
commit 32e1bc6aa5
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 39 additions and 5 deletions

View File

@ -90,18 +90,18 @@ class ChaindFsAdapter(ChaindAdapter):
def succeed(self, block, tx): def succeed(self, block, tx):
if self.store.is_reserved(tx.hash): if self.store.is_reserved(tx.hash):
raise QueueLockError(tx.hash) raise QueueLockError(tx.hash)
r = self.store.final(tx.hash, block, tx, error=False) 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 return r
def fail(self, block, tx): def fail(self, block, tx):
if self.store.is_reserved(tx.hash): if self.store.is_reserved(tx.hash):
raise QueueLockError(tx.hash) raise QueueLockError(tx.hash)
r = self.store.final(tx.hash, block, tx, error=True) 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 return r

34
chaind/lock.py Normal file
View 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

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = chaind name = chaind
version = 0.2.2 version = 0.2.3
description = Base package for chain queue service description = Base package for chain queue service
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no