From 03192a830a0281a7bbacfdaeaeeffbfe5b3acf76 Mon Sep 17 00:00:00 2001 From: Jiri Kozel Date: Mon, 27 Nov 2023 16:06:10 +0100 Subject: [PATCH] WIP --- src/layman/layer/util.py | 80 +++++++++++++++++++++++----------------- src/layman/util.py | 8 +++- 2 files changed, 52 insertions(+), 36 deletions(-) diff --git a/src/layman/layer/util.py b/src/layman/layer/util.py index 7ec52d619..2fccde82d 100644 --- a/src/layman/layer/util.py +++ b/src/layman/layer/util.py @@ -85,43 +85,55 @@ def clear_publication_info(layer_info, file_type): def get_complete_layer_info(workspace, layername, *, x_forwarded_items=None): - partial_info = get_layer_info(workspace, layername, context={'x_forwarded_items': x_forwarded_items}) + is_updating_before = layman_util.is_publication_updating(workspace, LAYER_TYPE, layername) + is_updating_after = None - if not any(partial_info): - raise LaymanError(15, {'layername': layername}) + complete_info = {} - geodata_type = partial_info['geodata_type'] - original_data_source = partial_info['original_data_source'] - item_keys = get_layer_info_keys(geodata_type=geodata_type, original_data_source=original_data_source) + logger.info(f"get_complete_layer_info START, is_updating_before={is_updating_before}") - complete_info = {} - for key in item_keys: - complete_info[key] = {'status': 'NOT_AVAILABLE'} - - complete_info.update({ - 'name': layername, - 'url': url_for('rest_workspace_layer.get', layername=layername, workspace=workspace, x_forwarded_items=x_forwarded_items), - 'title': layername, - 'description': '', - }) - if original_data_source == settings.EnumOriginalDataSource.FILE.value and partial_info.get('db', {}).get('table') is not None: - partial_info['db_table'] = { - 'name': partial_info['db']['table'], - } - - complete_info.update(partial_info) - complete_info['sld'] = complete_info['style'] - file_type = complete_info.get('_file', {}).get('file_type') - if complete_info['geodata_type'] == settings.GEODATA_TYPE_UNKNOWN and file_type and file_type != settings.GEODATA_TYPE_UNKNOWN: - complete_info['geodata_type'] = file_type - if 'file' in complete_info: - complete_info['file']['file_type'] = complete_info['geodata_type'] - - complete_info = clear_publication_info(complete_info, geodata_type) - - complete_info.pop('layman_metadata') - complete_info['layman_metadata'] = {'publication_status': layman_util.get_publication_status(workspace, LAYER_TYPE, layername, - complete_info, item_keys)} + while is_updating_before != is_updating_after: + if is_updating_after is not None: + is_updating_before = is_updating_after + partial_info = get_layer_info(workspace, layername, context={'x_forwarded_items': x_forwarded_items}) + + if not any(partial_info): + raise LaymanError(15, {'layername': layername}) + + geodata_type = partial_info['geodata_type'] + original_data_source = partial_info['original_data_source'] + item_keys = get_layer_info_keys(geodata_type=geodata_type, original_data_source=original_data_source) + + complete_info = {} + for key in item_keys: + complete_info[key] = {'status': 'NOT_AVAILABLE'} + + complete_info.update({ + 'name': layername, + 'url': url_for('rest_workspace_layer.get', layername=layername, workspace=workspace, x_forwarded_items=x_forwarded_items), + 'title': layername, + 'description': '', + }) + if original_data_source == settings.EnumOriginalDataSource.FILE.value and partial_info.get('db', {}).get('table') is not None: + partial_info['db_table'] = { + 'name': partial_info['db']['table'], + } + + complete_info.update(partial_info) + complete_info['sld'] = complete_info['style'] + file_type = complete_info.get('_file', {}).get('file_type') + if complete_info['geodata_type'] == settings.GEODATA_TYPE_UNKNOWN and file_type and file_type != settings.GEODATA_TYPE_UNKNOWN: + complete_info['geodata_type'] = file_type + if 'file' in complete_info: + complete_info['file']['file_type'] = complete_info['geodata_type'] + + complete_info = clear_publication_info(complete_info, geodata_type) + + complete_info.pop('layman_metadata') + publication_status = layman_util.get_publication_status(workspace, LAYER_TYPE, layername, complete_info, item_keys) + is_updating_after = publication_status == 'UPDATING' + logger.info(f"get_complete_layer_info, is_updating_after={is_updating_after}, publication_status={publication_status}") + complete_info['layman_metadata'] = {'publication_status': publication_status} return complete_info diff --git a/src/layman/util.py b/src/layman/util.py index e1e9d545d..ea9e41462 100644 --- a/src/layman/util.py +++ b/src/layman/util.py @@ -551,7 +551,7 @@ def patch_after_feature_change(workspace, publication_type, publication, *, queu celery_util.set_publication_chain_info(workspace, publication_type, publication, task_methods, res) -def get_publication_status(workspace, publication_type, publication_name, complete_info, item_keys, ): +def is_publication_updating(workspace, publication_type, publication_name): chain_info = celery_util.get_publication_chain_info(workspace, publication_type, publication_name) current_lock = redis.get_publication_lock( workspace, @@ -559,7 +559,11 @@ def get_publication_status(workspace, publication_type, publication_name, comple publication_name, ) - if (chain_info and not celery_util.is_chain_ready(chain_info)) or current_lock: + return bool((chain_info and not celery_util.is_chain_ready(chain_info)) or current_lock) + + +def get_publication_status(workspace, publication_type, publication_name, complete_info, item_keys, ): + if is_publication_updating(workspace, publication_type, publication_name): publication_status = 'UPDATING' elif any(complete_info.get(v, {}).get('status') for v in item_keys if isinstance(complete_info.get(v, {}), dict)): publication_status = 'INCOMPLETE'