Skip to content

Commit

Permalink
Merge pull request #354 from openimis/feature/wait-mutation
Browse files Browse the repository at this point in the history
OP-2314 wait for mutation
  • Loading branch information
delcroip authored Nov 8, 2024
2 parents d3aa537 + 3ab32bd commit 6361fd7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
10 changes: 9 additions & 1 deletion core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions core/services/__init__.py
Original file line number Diff line number Diff line change
@@ -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

15 changes: 13 additions & 2 deletions core/services/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit 6361fd7

Please sign in to comment.