def finish_publication_chain(last_task_id_in_chain): rds = settings.LAYMAN_REDIS key = LAST_TASK_ID_IN_CHAIN_TO_PUBLICATION hash = last_task_id_in_chain publ_hash = rds.hget(key, hash) if publ_hash is None: return username, publication_type, publication_name = _hash_to_publication( publ_hash) chain_info = get_publication_chain_info_dict(username, publication_type, publication_name) chain_info['finished'] = True set_publication_chain_info_dict(username, publication_type, publication_name, chain_info) rds.hdel(key, hash) lock = redis_util.get_publication_lock(username, publication_type, publication_name) if lock in [ common.REQUEST_METHOD_PATCH, common.REQUEST_METHOD_POST, common.PUBLICATION_LOCK_FEATURE_CHANGE, ]: redis_util.unlock_publication(username, publication_type, publication_name)
def get_publication_status( workspace, publication_type, publication_name, complete_info, item_keys, ): 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: publication_status = 'UPDATING' elif any( complete_info.get(v, dict()).get('status') for v in item_keys if isinstance(complete_info.get(v, dict()), dict)): publication_status = 'INCOMPLETE' else: publication_status = 'COMPLETE' return publication_status
def finish_publication_chain(last_task_id_in_chain, state): rds = settings.LAYMAN_REDIS key = LAST_TASK_ID_IN_CHAIN_TO_PUBLICATION hash = last_task_id_in_chain publ_hash = rds.hget(key, hash) if publ_hash is None: return workspace, publication_type, publication_name = _hash_to_publication( publ_hash) rds.hdel(key, hash) set_publication_chain_finished(workspace, publication_type, publication_name, state) lock = redis_util.get_publication_lock(workspace, publication_type, publication_name) if lock in [ common.REQUEST_METHOD_PATCH, common.REQUEST_METHOD_POST, common.PUBLICATION_LOCK_FEATURE_CHANGE, ]: redis_util.unlock_publication(workspace, publication_type, publication_name)
def test_patch_after_feature_change_concurrency(publication_type): workspace = 'test_wfst_concurrency_workspace' publication = 'test_wfst_concurrency_layer' process_client.publish_workspace_publication( publication_type, workspace, publication, ) queue = celery.get_run_after_chain_queue(workspace, publication_type, publication) assert not queue lock = redis.get_publication_lock(workspace, publication_type, publication) assert not lock with app.app_context(): layman_util.patch_after_feature_change(workspace, publication_type, publication) queue = celery.get_run_after_chain_queue(workspace, publication_type, publication) assert len(queue) == 0, queue lock = redis.get_publication_lock(workspace, publication_type, publication) assert lock == common_const.PUBLICATION_LOCK_FEATURE_CHANGE process_client.patch_workspace_publication( publication_type, workspace, publication, title='New title', check_response_fn=empty_method_returns_true) queue = celery.get_run_after_chain_queue(workspace, publication_type, publication) assert len(queue) == 1, queue assert queue == [ 'layman.util::patch_after_feature_change', ] lock = redis.get_publication_lock(workspace, publication_type, publication) assert lock == common_const.PUBLICATION_LOCK_PATCH or not lock with app.app_context(): layman_util.patch_after_feature_change(workspace, publication_type, publication) queue = celery.get_run_after_chain_queue(workspace, publication_type, publication) assert len(queue) == 1, queue assert queue == [ 'layman.util::patch_after_feature_change', ] lock = redis.get_publication_lock(workspace, publication_type, publication) assert lock == common_const.PUBLICATION_LOCK_FEATURE_CHANGE with app.app_context(): layman_util.patch_after_feature_change(workspace, publication_type, publication) queue = celery.get_run_after_chain_queue(workspace, publication_type, publication) assert len(queue) == 1, queue assert queue == [ 'layman.util::patch_after_feature_change', ] lock = redis.get_publication_lock(workspace, publication_type, publication) assert lock == common_const.PUBLICATION_LOCK_FEATURE_CHANGE process_client.wait_for_publication_status(workspace, publication_type, publication) queue = celery.get_run_after_chain_queue(workspace, publication_type, publication) assert not queue, queue lock = redis.get_publication_lock(workspace, publication_type, publication) assert not lock process_client.delete_workspace_publication( publication_type, workspace, publication, ) queue = celery.get_run_after_chain_queue(workspace, publication_type, publication) assert not queue, queue lock = redis.get_publication_lock(workspace, publication_type, publication) assert not lock