diff --git a/core/schema.py b/core/schema.py index fe96f46..47cd525 100644 --- a/core/schema.py +++ b/core/schema.py @@ -28,7 +28,8 @@ change_user_password, reset_user_password, set_user_password, - user_authentication + user_authentication, + wait_for_mutation ) from core.tasks import openimis_mutation_async from core import filter_validity @@ -793,6 +794,7 @@ def resolve_interactive_users(self, info, **kwargs): client_mutation_id = kwargs.get("client_mutation_id", None) if client_mutation_id: + wait_for_mutation(client_mutation_id) filters.append(Q(mutations__mutation__client_mutation_id=client_mutation_id)) show_history = kwargs.get('show_history', False) @@ -848,6 +850,7 @@ def resolve_users(self, info, email=None, last_name=None, other_names=None, phon client_mutation_id = kwargs.get("client_mutation_id", None) if client_mutation_id: + wait_for_mutation(client_mutation_id) user_filters.append(Q(mutations__mutation__client_mutation_id=client_mutation_id)) if email: @@ -936,7 +939,9 @@ def resolve_role(self, info, **kwargs): filters.append(Q(name__icontains=text_search)) client_mutation_id = kwargs.get("client_mutation_id", None) + if client_mutation_id: + wait_for_mutation(client_mutation_id) filters.append(Q(mutations__mutation__client_mutation_id=client_mutation_id)) show_history = kwargs.get('show_history', False) @@ -1150,6 +1155,7 @@ def update_or_create_role(data, user): } ) for right_id in rights_id] if client_mutation_id: + wait_for_mutation(client_mutation_id) RoleMutation.object_mutated(user, role=role, client_mutation_id=client_mutation_id) return role return role @@ -1206,6 +1212,7 @@ def duplicate_role(data, user): ) for role_right in role_rights_currently_assigned] if client_mutation_id: + wait_for_mutation(client_mutation_id) RoleMutation.object_mutated(user, role=duplicated_role, client_mutation_id=client_mutation_id) return duplicated_role @@ -1581,6 +1588,7 @@ def update_or_create_user(data, user): user_uuid=user_uuid, username=username, i_user=i_user, officer=officer, claim_admin=claim_admin) if client_mutation_id: + wait_for_mutation(client_mutation_id) UserMutation.object_mutated(user, core_user=core_user, client_mutation_id=client_mutation_id) return core_user diff --git a/core/services/__init__.py b/core/services/__init__.py index 2c85290..f263e1d 100644 --- a/core/services/__init__.py +++ b/core/services/__init__.py @@ -1,5 +1,6 @@ -from core.services.base import BaseService +from core.services.base import BaseService, wait_for_mutation from core.services.userServices import create_or_update_interactive_user, create_or_update_user_roles, \ create_or_update_user_districts, create_or_update_officer_villages, create_or_update_officer, \ create_or_update_claim_admin, create_or_update_core_user, change_user_password, set_user_password, \ - reset_user_password, user_authentication + reset_user_password, user_authentication + diff --git a/core/services/base.py b/core/services/base.py index 1659807..8886216 100644 --- a/core/services/base.py +++ b/core/services/base.py @@ -1,9 +1,9 @@ from abc import ABC from typing import Type - +import asyncio from django.db import transaction -from core.models import HistoryModel +from core.models import HistoryModel, MutationLog from core.services.utils import check_authentication as check_authentication, output_exception, \ model_representation, output_result_success, build_delete_instance_payload from core.validation.base import BaseModelValidation @@ -72,3 +72,14 @@ def _adjust_update_payload(self, payload_data): def _base_payload_adjust(self, obj_data): return obj_data + + +def wait_for_mutation(client_mutation_id): + mutation = MutationLog(client_mutation_id=client_mutation_id) + if not mutation: + return + loop_count = 0 + while mutation.status == MutationLog.RECEIVED and loop_count<10: + asyncio.sleep(0.3) + loop_count+= 1 + return \ No newline at end of file