Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed SDAP startup behavior to wait for all datasets to be ready #314

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 14 additions & 2 deletions analysis/webservice/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import logging
import sys
import os
from datetime import datetime

import tornado.web
from tornado.routing import Rule, RuleRouter, AnyMatches
Expand All @@ -27,6 +28,8 @@
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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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()
main()
17 changes: 11 additions & 6 deletions data-access/nexustiles/nexustiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def wrapper(*args, **kwargs):


SOLR_LOCK = threading.Lock()
DS_LOCK = threading.Lock()
thread_local = threading.local()


Expand All @@ -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)

Expand Down Expand Up @@ -164,12 +165,16 @@ def __init__(self, config=None):

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')
Expand Down Expand Up @@ -300,7 +305,7 @@ def user_ds_update(name, config):

logger.info(f'Updated dataset {name} in Solr. Updating backends')

with DS_LOCK:
with NexusTileService.DS_LOCK:
NexusTileService._update_datasets()

return {'success': True}
Expand Down Expand Up @@ -332,7 +337,7 @@ def user_ds_add(name, path, config, type='zarr'):

logger.info(f'Added dataset {name} to Solr. Updating backends')

with DS_LOCK:
with NexusTileService.DS_LOCK:
NexusTileService._update_datasets()

return {'success': True}
Expand All @@ -357,7 +362,7 @@ def user_ds_delete(name):

logger.info(f'Removed dataset {name} from Solr. Updating backends')

with DS_LOCK:
with NexusTileService.DS_LOCK:
NexusTileService._update_datasets()

return {'success': True}
Expand Down