This is an automated email from the ASF dual-hosted git repository.
rkk pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/sdap-nexus.git
The following commit(s) were added to refs/heads/develop by this push:
new 19ce6ac Changed SDAP startup behavior to wait for all datasets to be
prepared before accepting HTTP requests (#314)
19ce6ac is described below
commit 19ce6ac0f771e1737d38418157d6cef3c82876e5
Author: Riley Kuttruff <[email protected]>
AuthorDate: Fri Jun 7 09:58:59 2024 -0700
Changed SDAP startup behavior to wait for all datasets to be prepared
before accepting HTTP requests (#314)
Co-authored-by: rileykk <[email protected]>
---
CHANGELOG.md | 1 +
analysis/webservice/webapp.py | 16 ++++++++++++++--
data-access/nexustiles/nexustiles.py | 17 +++++++++++------
3 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 895931d..b39a232 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@ and this project adheres to [Semantic
Versioning](https://semver.org/spec/v2.0.0
- Added `dask` dependency
- Code cleanup
- Zarr: Fixed handling of times conversion from xr/np datetimes to Unix
timestamps
+- Changed SDAP startup behavior to wait for all datasets to be prepared before
accepting HTTP requests
### Deprecated
### Removed
- SDAP-493:
diff --git a/analysis/webservice/webapp.py b/analysis/webservice/webapp.py
index 0549863..9b11e6a 100644
--- a/analysis/webservice/webapp.py
+++ b/analysis/webservice/webapp.py
@@ -18,6 +18,7 @@ import configparser
import logging
import sys
import os
+from datetime import datetime
import tornado.web
from tornado.routing import Rule, RuleRouter, AnyMatches
@@ -27,6 +28,8 @@ from webservice.redirect import RemoteCollectionMatcher
from webservice.nexus_tornado.app_builders import NexusAppBuilder
from webservice.nexus_tornado.app_builders import RedirectAppBuilder
+from nexustiles.nexustiles import NexusTileService
+
try:
from importlib.metadata import version as _version
from importlib.metadata import files as _files
@@ -70,6 +73,8 @@ def inject_args_in_config(args, config):
def main():
+ start = datetime.now()
+
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
@@ -137,9 +142,16 @@ def main():
log.info("Starting web server in debug mode: %s" % options.debug)
server = tornado.web.HTTPServer(router)
server.listen(options.port)
- log.info("Starting HTTP listener...")
+ log.info('Waiting for dataset backends to come up...')
+
+ with NexusTileService.DS_LOCK:
+ if not NexusTileService.is_update_thread_alive():
+ log.critical('A fatal error occurred when loading the datasets')
+ exit(-1)
+
+ log.info(f"SDAP started in {datetime.now() - start}. Starting HTTP
listener...")
tornado.ioloop.IOLoop.current().start()
if __name__ == "__main__":
- main()
\ No newline at end of file
+ main()
diff --git a/data-access/nexustiles/nexustiles.py
b/data-access/nexustiles/nexustiles.py
index 51046f8..408799b 100644
--- a/data-access/nexustiles/nexustiles.py
+++ b/data-access/nexustiles/nexustiles.py
@@ -107,7 +107,6 @@ def catch_not_implemented(func):
SOLR_LOCK = threading.Lock()
-DS_LOCK = threading.Lock()
thread_local = threading.local()
@@ -126,12 +125,14 @@ class NexusTileService:
ds_config = None
+ DS_LOCK = threading.Lock()
+
__update_thread = None
@staticmethod
def __update_datasets_loop():
while True:
- with DS_LOCK:
+ with NexusTileService.DS_LOCK:
NexusTileService._update_datasets()
sleep(3600)
@@ -164,12 +165,16 @@ class NexusTileService:
NexusTileService.__update_thread.start()
+ @staticmethod
+ def is_update_thread_alive() -> bool:
+ return NexusTileService.__update_thread is not None and
NexusTileService.__update_thread.is_alive()
+
@staticmethod
def _get_backend(dataset_s) -> AbstractTileService:
if dataset_s is not None:
dataset_s = dataset_s
- with DS_LOCK:
+ with NexusTileService.DS_LOCK:
if dataset_s not in NexusTileService.backends:
logger.warning(f'Dataset {dataset_s} not currently loaded.
Checking to see if it was recently'
f'added')
@@ -300,7 +305,7 @@ class NexusTileService:
logger.info(f'Updated dataset {name} in Solr. Updating backends')
- with DS_LOCK:
+ with NexusTileService.DS_LOCK:
NexusTileService._update_datasets()
return {'success': True}
@@ -332,7 +337,7 @@ class NexusTileService:
logger.info(f'Added dataset {name} to Solr. Updating backends')
- with DS_LOCK:
+ with NexusTileService.DS_LOCK:
NexusTileService._update_datasets()
return {'success': True}
@@ -357,7 +362,7 @@ class NexusTileService:
logger.info(f'Removed dataset {name} from Solr. Updating backends')
- with DS_LOCK:
+ with NexusTileService.DS_LOCK:
NexusTileService._update_datasets()
return {'success': True}