Skip to content

Commit

Permalink
Make sure, publication is deleted even if asynchronous tasks are stil…
Browse files Browse the repository at this point in the history
…l running
  • Loading branch information
index-git committed May 18, 2021
1 parent 678a7d2 commit f83833d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/layman/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from celery.contrib.abortable import AbortableAsyncResult

from layman.publication_relation.util import update_related_publications_after_change
from layman import settings, common
from layman import settings, common, util as layman_util
from layman.common import redis as redis_util

REDIS_CURRENT_TASK_NAMES = f"{__name__}:CURRENT_TASK_NAMES"
Expand Down Expand Up @@ -47,6 +47,14 @@ def task_postrun(workspace, publication_type, publication_name, task_id, task_na
last_task_id = chain_info['last']
finish_publication_chain(last_task_id)
clear_steps_to_run_after_chain(workspace, publication_type, publication_name)
# Sometimes, when delete request run just after other request for the same publication (for example WFS-T),
# the aborted task keep running and finish after end of delete task for the same source. This part make sure,
# that in that case we delete it.
info = layman_util.get_publication_info(workspace, publication_type, publication_name, context={'keys': ['name']})
if not info:
current_app.logger.warning(f"POST task={task_name}, workspace={workspace}, publication_type={publication_type},"
f"publication_name={publication_name} Publication does not exist, so we delete it")
layman_util.delete_workspace_publication(workspace, publication_type, publication_name)


def _get_task_hash(task_name, workspace, publication_name):
Expand Down
2 changes: 0 additions & 2 deletions src/layman/geoserver_proxy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ def wfs_post(workspace, attr_names_list, data_xml):
data_xml = data_wfs.get_wfs11_insert_polygon_new_attr(username, layername, attr_names10)
wfs_post(username, [(layername, attr_names10)], data_xml)

process_client.wait_for_publication_status(username, process_client.LAYER_TYPE, layername, headers=authn_headers)
process_client.delete_workspace_layer(username, layername, headers=authn_headers)
process_client.delete_workspace_layer(username, layername2, headers=authn_headers)

Expand Down Expand Up @@ -293,7 +292,6 @@ def do_test(wfs_query, attribute_names):
data_xml = data_wfs.get_wfs20_update_points_new_attr(username, layername1, attr_names)
do_test(data_xml, attr_names)

process_client.wait_for_publication_status(username, process_client.LAYER_TYPE, layername1, headers=authn_headers1)
process_client.delete_workspace_layer(username, layername1, headers=authn_headers1)


Expand Down
2 changes: 0 additions & 2 deletions src/layman/layer/empty_bbox_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,4 @@ def test_empty_shapefile(layername, file_paths):
assert wms_layer.boundingBox == native_bbox
assert wms_layer.boundingBoxWGS84 == wgs_bbox

process_client.wait_for_publication_status(workspace, process_client.LAYER_TYPE, layername)

process_client.delete_workspace_layer(workspace, layername)
6 changes: 4 additions & 2 deletions src/layman/layer/micka/csw.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ def patch_layer(workspace, layername, metadata_properties_to_refresh, _actor_nam
return muuid


def delete_layer(workspace, layername):
uuid = get_layer_uuid(workspace, layername)
def delete_layer(workspace, layername, *, backup_uuid=None):
uuid = get_layer_uuid(workspace, layername) or backup_uuid
if backup_uuid and uuid:
assert backup_uuid == uuid
muuid = get_metadata_uuid(uuid)
if muuid is None:
return
Expand Down
13 changes: 12 additions & 1 deletion src/layman/layer/micka/soap_tasks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from celery.utils.log import get_task_logger

from layman.celery import AbortedException
from layman import celery_app
from layman import celery_app, util as layman_util
from . import soap
from .. import LAYER_TYPE

logger = get_task_logger(__name__)

Expand All @@ -19,8 +20,18 @@ def patch_after_feature_change(
):
if self.is_aborted():
raise AbortedException
uuid = layman_util.get_publication_info(workspace, LAYER_TYPE, layer, context={'keys': ['uuid']})['uuid']

soap.patch_layer(workspace, layer, metadata_properties_to_refresh=['extent'])

# Sometimes, when delete request run just after other request for the same publication (for example WFS-T),
# the aborted task keep running and finish after end of delete task for the same source. This part make sure,
# that in that case we delete it.
info = layman_util.get_publication_info(workspace, LAYER_TYPE, layer, context={'keys': ['name']})
if not info:
logger.warning(f"layman.layer.micka.soap.patch_after_feature_change: workspace={workspace}, "
f"layer={layer}, uuid={uuid} Publication does not exist, so we delete it")
soap.delete_layer(workspace, layer, backup_uuid=uuid)

if self.is_aborted():
raise AbortedException
12 changes: 12 additions & 0 deletions src/layman/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,18 @@ def get_publication_infos_with_metainfo(workspace=None, publ_type=None, context=
return infos


def delete_workspace_publication(workspace, publication_type, publication):
from layman.layer import LAYER_TYPE, util as layer_util
from layman.map import MAP_TYPE, util as map_util

delete_method = {
LAYER_TYPE: layer_util.delete_layer,
MAP_TYPE: map_util.delete_map,
}[publication_type]

delete_method(workspace, publication)


def delete_publications(user,
publ_type,
error_code,
Expand Down

0 comments on commit f83833d

Please sign in to comment.