Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jirik committed Nov 27, 2023
1 parent 2aae5cc commit 03192a8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 36 deletions.
80 changes: 46 additions & 34 deletions src/layman/layer/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 6 additions & 2 deletions src/layman/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,15 +551,19 @@ 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,
publication_type,
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'
Expand Down

0 comments on commit 03192a8

Please sign in to comment.