-
Notifications
You must be signed in to change notification settings - Fork 1
To implement a Generic Interpretation Workflow Function #24
Copy link
Copy link
Open
Description
Background
All interpretation functions currently follow the same high-level workflow:
- Copy RunningDS into CandidateDS
- Lock CandidateDS
- Update the data in CandidateDS
- Perform validation
- If validation succeeds (204):
- Respond 204 to the REST call
- Lock RunningDS and copy CandidateDS into RunningDS
- 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels