Skip to content

Commit cad6b60

Browse files
committed
enh: detect DCOR maintenance mode
1 parent 9c43691 commit cad6b60

5 files changed

Lines changed: 36 additions & 4 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
0.17.0
22
- BREAKING CHANGE: migrate codebase from PyQt5 to PyQt6
3+
- enh: detect DCOR maintenance mode
34
- tests: allow to use different DCOR instance for testing
45
- tests: make tests independent of testing user
56
0.16.11

dcoraid/api/ckan_api.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
from .errors import (APIConflictError, APINotFoundError, NoAPIKeyError,
1818
APIBadGatewayError, APIBadRequest, APIGatewayTimeoutError,
19-
APIAuthorizationError, APIOutdatedError)
19+
APIAuthorizationError, APIOutdatedError,
20+
ServerUnderMaintenanceError)
2021

2122
#: Minimum required CKAN version on the server side
2223
MIN_CKAN_VERSION = "2.9.4"
@@ -267,6 +268,17 @@ def is_available(self, with_api_key=False, with_correct_version=False):
267268
status = True
268269
return status
269270

271+
def is_under_maintenance(self):
272+
"""Check whether DCOR is under maintenance"""
273+
maintenance = False
274+
try:
275+
self.get("status_show")
276+
except ServerUnderMaintenanceError:
277+
maintenance = True
278+
except BaseException:
279+
pass
280+
return maintenance
281+
270282
def get(self,
271283
api_call: str,
272284
timeout: float = 27.9,
@@ -302,6 +314,10 @@ def get(self,
302314
headers=self.headers,
303315
verify=self.verify,
304316
timeout=timeout)
317+
318+
if req.status_code == 503:
319+
raise ServerUnderMaintenanceError(
320+
"DCOR under maintenance. Please try again later.")
305321
rdata = self.handle_response(req, api_call)
306322
return rdata["result"]
307323

dcoraid/api/errors.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,10 @@ class NoS3UploadAvailableError(BaseException):
4949

5050

5151
class S3UploadError(BaseException):
52-
"""raised when an upload to S3 failed"""
52+
"""Raised when an upload to S3 failed"""
53+
pass
54+
55+
56+
class ServerUnderMaintenanceError(BaseException):
57+
"""Raised when the DCOR server is under maintenance"""
5358
pass

dcoraid/gui/status_widget.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ def run(self):
116116
api = get_ckan_api()
117117

118118
if not api.is_available():
119-
text = "No connection"
120-
tip = f"Can you access {api.server} via a browser?"
119+
if api.is_under_maintenance():
120+
text = "Under Maintenance"
121+
tip = "Please wait until maintenance is complete"
122+
else:
123+
text = "No connection"
124+
tip = f"Can you access {api.server} via a browser?"
121125
icon = "hourglass"
122126
elif not api.is_available(with_correct_version=True):
123127
text = "Server out of date"

tests/test_api_base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
from . import common
88

99

10+
def test_api_no_maintenance():
11+
"""Normally, the DCOR instance should not be under maintenance"""
12+
api = common.get_api()
13+
assert not api.is_under_maintenance()
14+
15+
1016
def test_api_requests_cache_no_parameters():
1117
"""Test the requests_cache for an API call *without* parameters"""
1218
api = common.get_api()

0 commit comments

Comments
 (0)