Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spike] Async execution of rules #1205

Open
Tracked by #1507 ...
himeshr opened this issue Apr 24, 2024 · 1 comment
Open
Tracked by #1507 ...

[Spike] Async execution of rules #1205

himeshr opened this issue Apr 24, 2024 · 1 comment
Assignees

Comments

@himeshr
Copy link
Contributor

himeshr commented Apr 24, 2024

Motivation

Requirement 1:

For avoiding duplicate phone numbers beyond 5, the idea is to just add an API endpoint and call it from form element rule when user enters the mobile number

Requirement 2:

As part of Epic avniproject/avni-product#1507 and Story #1171, we encountered an issue while evaluating rules for Goonj organisation, for creation of Distribution.
We are linking Activities to a distribution, by doing a search and select of Subject. This is then used within FormElement rule to initialize certain fields. For this purpose, we make use of individualService.getSubjectByUUID() call in the rules.
(on distribution registration, activity's pariticipants will not get immediately populated after selecting an activity.)

RuleEvaluationService in webapp has a problem while fetching a different individual using its uuid.
The rule written for client, assumes that individualServiceFacade will always be able to fetch the individual in a synchronous manner, which works fine there as its connected to the realm DB. But on the web-app, we need to fetch the individual from the backendServer asynchronously as a remote call.

This results in 2 Major behaviourial changes:

  1. Within any rule, whenever we need to fetch the Subject, we would need to figure out a way to handle the Promise returned by the async facade service fetch calls on the webapp, while simultaneously working correctly on the client in a synchronous manner.
  2. Provide ability to invoke RuleEvaluationService in an asynchronous manner, to be able to invoke an async call and resolve it.

Acceptance Criteria

  • We are able to run the same FormElement rule which uses following services methods in both webapp and client.

Service Methods

individualService.getSubjectByUUID
individualService.getSubjectsInLocation
addressLevelService.findAddressLevelByUUID

  • In webapp after this change, soon after selection of activity in distribution registration, value for 'Total participants in the activity' field should get populated. Currently it gets populated only after entering value in some other field(ie., only after rule corresponding to 'Total participants in the activity' runs 2 times)

Tech Approach

Needs more Technical evaluation.
Current solutions for each of the above problem:

  1. In this scenario, we could run a string replace query on the rule content to replace all "individualService.getSubjectByUUID(" with "await individualService.getSubjectByUUID(" in webapp at runtime.
    Also, we need to make the rule function async by prefixing the keyword "async" only in webapp.

  2. For this, we would prefer to only make the RuleEvaluation related entities data init, update and rule execution to be encapsulated within the FormWizard and run in Asynchronous manner, while rest of the Webapp working as is in a synchronous manner.

Additional Information

The list of impacted Orgs and Elements with rules that need asynchronous api calls is as per below attached file.
InstancesOfRuleInDB.txt

AC:

Figure out the below:

  • Is supporting both sync and async execution of rules feasible at the same time/common code
  • Would it need update of existing rules in db and if yes, more details on the same.
  • How will execution of old rules get impacted
  • How many days will it take to complete the above if it is feasible.
@github-project-automation github-project-automation bot moved this to New Issues in Avni Product Apr 24, 2024
@himeshr himeshr added the DEA Data Entry App label Apr 24, 2024
@himeshr himeshr moved this from New Issues to Focus Items in Avni Product Apr 24, 2024
@mahalakshme mahalakshme changed the title Handle Async fetch of related entities during Rule Evaluation in DEA [DEA] Handle Async fetch of related entities during Rule Evaluation Jun 13, 2024
@mahalakshme mahalakshme moved this from Focus Items to Ready in Avni Product Jul 25, 2024
@mahalakshme mahalakshme moved this from Ready to In Analysis Review in Avni Product Jul 25, 2024
@mahalakshme mahalakshme changed the title [DEA] Handle Async fetch of related entities during Rule Evaluation [Spike] Async execution of rules Dec 10, 2024
@mahalakshme mahalakshme removed the DEA Data Entry App label Dec 10, 2024
@mahalakshme mahalakshme moved this from In Analysis to Ready in Avni Product Dec 10, 2024
@petmongrels petmongrels moved this from Ready to QA Failed in Avni Product Dec 10, 2024
@petmongrels petmongrels self-assigned this Dec 10, 2024
@1t5j0y 1t5j0y moved this from QA Failed to In Progress in Avni Product Dec 10, 2024
@petmongrels
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

No branches or pull requests

3 participants