Skip to content

Commit e82387d

Browse files
committed
The confirmation wait time is fixed at 1200s
Problem: 20minutes is a long time to wait for failure. Tenant storage assets should confirm more quckly and this setting must be optionally settable by user. Solution: Specify new value via optional argument to Archivist() class. Setting confirm=True when creating assets or events will then terminate after this time if unconfirmed. Signed-off-by: Paul Hewlett <phewlett76@gmail.com>
1 parent 59a5153 commit e82387d

7 files changed

Lines changed: 34 additions & 20 deletions

File tree

archivist/archivist.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
)
5757

5858
from .assets import _AssetsClient
59+
from .confirmer import MAX_TIME
5960
from .events import _EventsClient
6061
from .locations import _LocationsClient
6162
from .attachments import _AttachmentsClient
@@ -86,6 +87,7 @@ class Archivist: # pylint: disable=too-many-instance-attributes
8687
auth: string representing JWT token.
8788
cert: filepath containing both private key and certificate
8889
verify: if True the certificate is verified
90+
max_time (int): maximum time in seconds to wait for confirmation
8991
9092
Raises:
9193
ArchivistIllegalArgumentError: if neither 'auth' and 'cert' or if
@@ -103,6 +105,7 @@ def __init__(
103105
auth: Optional[str] = None,
104106
cert: Optional[str] = None,
105107
verify: bool = True,
108+
max_time: int = MAX_TIME,
106109
):
107110

108111
self._headers = {"content-type": "application/json"}
@@ -126,6 +129,7 @@ def __init__(
126129
self._cert = cert
127130
self._response_ring_buffer = deque(maxlen=self.RING_BUFFER_MAX_LEN)
128131
self._session = requests.Session()
132+
self._max_time = max_time
129133

130134
# keep these in sync with CLIENTS map above
131135
self.assets: _AssetsClient
@@ -161,6 +165,11 @@ def verify(self) -> bool:
161165
"""bool: Returns True if https connections are to be verified"""
162166
return self._verify
163167

168+
@property
169+
def max_time(self) -> int:
170+
"""bool: Returns maximum time in seconds to wait for confirmation"""
171+
return self._max_time
172+
164173
@property
165174
def cert(self) -> Optional[str]:
166175
"""str: filepath containing authorisation certificate."""

archivist/assets.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@
3838
ASSETS_LABEL,
3939
CONFIRMATION_STATUS,
4040
)
41-
from .confirm import _wait_for_confirmation, _wait_for_confirmed
41+
from . import confirmer
4242
from .errors import ArchivistNotFoundError
4343

44-
4544
#: Default page size - number of entities fetched in one REST GET in the
4645
#: :func:`~_AssetsClient.list` method. This can be overridden but should rarely
4746
#: be changed.
@@ -166,7 +165,7 @@ def create_from_data(self, data: Dict, *, confirm: bool = False) -> Asset:
166165
if not confirm:
167166
return asset
168167

169-
return _wait_for_confirmation(self, asset["identity"]) # type: ignore
168+
return self.wait_for_confirmation(asset["identity"])
170169

171170
def wait_for_confirmation(self, identity: str) -> bool:
172171
"""Wait for asset to be confirmed.
@@ -180,7 +179,9 @@ def wait_for_confirmation(self, identity: str) -> bool:
180179
True if asset is confirmed.
181180
182181
"""
183-
return _wait_for_confirmation(self, identity)
182+
confirmer.MAX_TIME = self._archivist.max_time
183+
# pylint: disable=protected-access
184+
return confirmer._wait_for_confirmation(self, identity)
184185

185186
def read(self, identity: str) -> Asset:
186187
"""Read asset
@@ -247,7 +248,9 @@ def wait_for_confirmed(
247248
if count == 0:
248249
raise ArchivistNotFoundError("No assets exist")
249250

250-
return _wait_for_confirmed(self, props=newprops, attrs=attrs)
251+
confirmer.MAX_TIME = self._archivist.max_time
252+
# pylint: disable=protected-access
253+
return confirmer._wait_for_confirmed(self, props=newprops, attrs=attrs)
251254

252255
def list(
253256
self,

archivist/events.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
CONFIRMATION_STATUS,
3838
EVENTS_LABEL,
3939
)
40-
from .confirm import _wait_for_confirmation, _wait_for_confirmed
40+
from . import confirmer
4141
from .errors import ArchivistNotFoundError
4242

4343

@@ -174,7 +174,7 @@ def create_from_data(self, asset_id: str, data: Dict, *, confirm=False) -> Event
174174
if not confirm:
175175
return event
176176

177-
return _wait_for_confirmation(self, event["identity"]) # type: ignore
177+
return self.wait_for_confirmation(event["identity"])
178178

179179
def wait_for_confirmation(self, identity: str) -> bool:
180180
"""Wait for event to be confirmed.
@@ -188,7 +188,9 @@ def wait_for_confirmation(self, identity: str) -> bool:
188188
True if event is confirmed.
189189
190190
"""
191-
return _wait_for_confirmation(self, identity)
191+
confirmer.MAX_TIME = self._archivist.max_time
192+
# pylint: disable=protected-access
193+
return confirmer._wait_for_confirmation(self, identity)
192194

193195
def read(self, identity: str) -> Event:
194196
"""Read event
@@ -282,7 +284,9 @@ def wait_for_confirmed(
282284
if count == 0:
283285
raise ArchivistNotFoundError("No events exist")
284286

285-
return _wait_for_confirmed(
287+
confirmer.MAX_TIME = self._archivist.max_time
288+
# pylint: disable=protected-access
289+
return confirmer._wait_for_confirmed(
286290
self, asset_id=asset_id, props=props, attrs=attrs, asset_attrs=asset_attrs
287291
)
288292

examples/create_asset.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,14 @@ def main():
9090
with open(".auth_token", mode="r") as tokenfile:
9191
authtoken = tokenfile.read().strip()
9292

93-
# Initialize connection to Archivist
93+
# Initialize connection to Archivist. max_time is the time to wait for confirmation
94+
# of an asset or event creation - the default is 1200 seconds but one can optionally
95+
# specify a differnet value here particularly when creating assets on TENANT_STORAGE
96+
# (rather than LEDGER) as confirmation times are much shorter in this case.
9497
arch = Archivist(
9598
"https://rkvst.poc.jitsuin.io",
9699
auth=authtoken,
100+
max_time=300,
97101
)
98102
# Create a new asset
99103
asset = create_asset(arch)

unittests/testassets.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from archivist.archivist import Archivist
1010
from archivist.assets import DEFAULT_PAGE_SIZE
11-
from archivist import confirm
1211
from archivist.constants import (
1312
ASSETS_LABEL,
1413
ASSETS_SUBPATH,
@@ -125,12 +124,10 @@ class TestAssets(TestCase):
125124
maxDiff = None
126125

127126
def setUp(self):
128-
self.arch = Archivist("url", auth="authauthauth")
129-
self.confirm_MAX_TIME = confirm.MAX_TIME
130-
confirm.MAX_TIME = 2
127+
self.arch = Archivist("url", auth="authauthauth", max_time=2)
131128

132129
def tearDown(self):
133-
confirm.MAX_TIME = self.confirm_MAX_TIME
130+
self.arch = None
134131

135132
def test_assets_create(self):
136133
"""

unittests/testevents.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from unittest import TestCase, mock
77

88
from archivist.archivist import Archivist
9-
from archivist import confirm
109
from archivist.constants import (
1110
ROOT,
1211
ASSETS_LABEL,
@@ -231,12 +230,10 @@ class TestEvents(TestCase):
231230
maxDiff = None
232231

233232
def setUp(self):
234-
self.arch = Archivist("url", auth="authauthauth")
235-
self.confirm_MAX_TIME = confirm.MAX_TIME
236-
confirm.MAX_TIME = 2
233+
self.arch = Archivist("url", auth="authauthauth", max_time=2)
237234

238235
def tearDown(self):
239-
confirm.MAX_TIME = self.confirm_MAX_TIME
236+
self.arch = None
240237

241238
def test_events_create(self):
242239
"""

0 commit comments

Comments
 (0)