Skip to content

To implement a Generic Interpretation Workflow Function #24

@PrathibaJee

Description

@PrathibaJee

Background

All interpretation functions currently follow the same high-level workflow:

  1. Copy RunningDS into CandidateDS
  2. Lock CandidateDS
  3. Update the data in CandidateDS
  4. Perform validation
  5. If validation succeeds (204):
    • Respond 204 to the REST call
    • Lock RunningDS and copy CandidateDS into RunningDS
  6. If validation fails (4xx/5xx):
    • Respond with the validation error

The only difference between these interpretation functions is the specific data they generate and apply inside CandidateDS.
All other operational steps are identical and should be unified into one reusable workflow function.


Goal

Create a generic workflow function that encapsulates the common logic shared by all interpretation functions.
This reduces duplication, simplifies maintenance, and ensures consistent behavior across services.

The workflow should follow this structure (modify as needed):

async function processWithCandidateDS({
    requestBody,
    doWorkInCandidate,        // operation-specific steps
    afterCommit = () => {}    // optional post-success actions
}) {
    try {
        // 1. Copy Running into Candidate
        await DataStore.copy("RunningDS", "CandidateDS");

        // 2. Lock CandidateDS
        await DataStore.lock("CandidateDS");

        // 3. Perform operation-specific steps
        await doWorkInCandidate(requestBody);

        // 4. Validate
        const validationResponse = await validationOrchestrator();

        if (validationResponse.status === 204) {

            // 5a. Commit Candidate into Running (no await as we have to return the response code )
            DataStore.copy("CandidateDS", "RunningDS");

            // 5b. Post-commit logic (operation-specific)(no await)
            afterCommit(requestBody);

            // 5c. Return OK
            return { status: 204 };

        } else {
            // 6a. Validation failed, return error
            return {
                status: validationResponse.status,
                body: validationResponse.body
            };
        }

    } finally {
        // 6b. Always unlock CandidateDS
        await DataStore.unlock("CandidateDS");
    }
}

Acceptance Criteria

  • Implement the generic processWithCandidateDS() function
  • Maintain complete functional behavior of both success and failure paths
  • Add unit tests for:
    • Successful validation (204 flow)
    • Failed validation (4xx/5xx flow)
    • CandidateDS lock/unlock behavior
  • Update documentation where needed

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions