commit 32e1bc6aa5976b5ffa3559296c55eefc5dd349d7
parent 387014f77ba38f47de0fa4562aa07393b7f18310
Author: lash <dev@holbrook.no>
Date: Mon, 2 May 2022 20:10:30 +0000
Correct purge call, add missing lock module
Diffstat:
3 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/chaind/adapters/fs.py b/chaind/adapters/fs.py
@@ -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
diff --git a/chaind/lock.py b/chaind/lock.py
@@ -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
diff --git a/setup.cfg b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = chaind
-version = 0.2.2
+version = 0.2.3
description = Base package for chain queue service
author = Louis Holbrook
author_email = dev@holbrook.no