Skip to content

#51 Submission Validation in a worker thread#197

Merged
leoraba merged 21 commits intomainfrom
feat/validate_data_worker
Mar 25, 2026
Merged

#51 Submission Validation in a worker thread#197
leoraba merged 21 commits intomainfrom
feat/validate_data_worker

Conversation

@leoraba
Copy link
Copy Markdown
Contributor

@leoraba leoraba commented Mar 11, 2026

Summary

This PR improves the performance of the submission data validation process.

Issues

Description of Changes

Data validation

  • Implemented a worker thread to perform submission data validation. (CPU intensive process running out of the main thread) to keep the main thread always available.
  • Worker thread is executed when data is validated in the following endpoints:
    • Add new data for a submission POST /submission/category/{categoryId}/data and POST /submission/category/{categoryId}/files
    • Delete submission data DELETE /submission/{submissionId}/{actionType}
    • Modify existing data for a submission PUT /submission/category/{categoryId}/data
    • Delete existing data for a submission DELETE /submission/category/{categoryId}/data/{systemId}
  • Before running the validation, the Submission status is updated to VALIDATING status, it prevents the Submission to be altered by other request during this state.

Database

  • Drizzle migration to add new enum VALIDATING on Submission status

Close Submission

  • Added a query param force on to DELETE /submission/{submissionId}. By design a VALIDATING or COMMITTING submissions cannot be deleted, unless this flag is provided.

@leoraba leoraba changed the base branch from main to commit_submission_worker March 11, 2026 22:17
}): Promise<number> => {
const { submissionId, submissionData, username } = input;

const performDataValidation = async (submissionId: number): Promise<number> => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is being executed by the worker thread, changed the params to receive only the submissionId it will load submission data from db within the worker thread

workerpool.worker({
initializeWorker,
commitSubmission,
performDataValidation,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding a function to the workerpool

Base automatically changed from commit_submission_worker to main March 20, 2026 12:45
Comment on lines -587 to -591
submissionData: {
inserts: submissionData.inserts,
deletes: submissionData.deletes,
updates: submissionData.updates,
},
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After validation is complete we do not need to update Submission data, instead it's passing an array of errors (schemaErrors), this function updates the submission status to INVALID where there are errors , or VALID if no errors

Copy link
Copy Markdown
Contributor

@joneubank joneubank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

I have a question about the state transition to OPEN before running validation... Have we properly considered how this interacts with receiving additional data to the active submission while the validation runs?

await submissionRepository.update(submission.id, {
data: updatedActiveSubmissionData,
updatedBy: username,
status: 'OPEN',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the correct state to set to while we run validation? Do we want to allow new data to be submitted while the validation runs?

Copy link
Copy Markdown
Contributor Author

@leoraba leoraba Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, there should be a blocking state for a submission between OPEN and VALID states, for example: VALIDATING.

Similarly, that state along with COMMITTING should be restricting any update on the submission (submit, edit, delete, commit). I will update this PR to add the proposed change.

Comment on lines +191 to 196
// Updating the Submission with the new data and 'VALIDATING' status before validation starts
await submissionRepository.update(submission.id, {
data: updatedActiveSubmissionData,
updatedBy: username,
status: 'VALIDATING',
});
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the submission status to VALIDATING

Comment on lines +371 to +373
if (!isSubmissionActive(activeSubmission.status)) {
throw new StatusConflict(`Existing submission with status '${activeSubmission.status}' cannot be modified`);
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing an error to avoid overriding a submission that is not OPEN, VALID or INVALID

@leoraba
Copy link
Copy Markdown
Contributor Author

leoraba commented Mar 24, 2026

PR Updated to add new submission status VALIDATING. This indicates the submission is being processed and cannot be updated by other requests while in this state.

Comment on lines +39 to +45
ForceDeleteSubmission:
description: Optional query parameter to force the deletion of a submission. Default value is false
name: force
in: query
schema:
type: boolean
required: false
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flag added to the DELETE submission endpoint.

@leoraba leoraba merged commit 7377424 into main Mar 25, 2026
2 checks passed
@leoraba leoraba deleted the feat/validate_data_worker branch March 25, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prod Issue: Loading the submission details page takes several minutes

2 participants