Conversation
| const invalidRecordErrors = findInvalidRecordErrorsBySchemaName(resultValidation, entityName); | ||
| const hasErrorByIndex = groupErrorsByIndex(invalidRecordErrors); |
There was a problem hiding this comment.
Move calling these 2 functions out of the for loop to improve the performance.
During local testing, this change improve 15x the performance during commit operation.
| return { | ||
| submissionId: submission.id, | ||
| organization: submission.organization, | ||
| categoryId: submission.dictionaryCategory.id, | ||
| data: resultCommit, | ||
| }; |
There was a problem hiding this comment.
Removed the execution of params.onFinishCommit from here, since this now runs on a worker thread and it doesn't have access to this function, instead this function just returns the data object
| categoryId, | ||
| submission?.organization, | ||
| ); | ||
| await submissionRepository.update(submissionId, { status: SUBMISSION_STATUS.COMMITTING, updatedBy: username }); |
There was a problem hiding this comment.
submission is updated to COMMITTING status when the commit operation is called
There was a problem hiding this comment.
refactor: updated this function to handle large arrays of submitted data more efficiently by replacing the spread operator, which previously created new arrays during each iteration and was using memory inefficiently.
| export interface WorkerFunctions { | ||
| commitSubmission(input: CommitWorkerInput): Promise<void>; | ||
| } |
There was a problem hiding this comment.
functions exposed are ran on a worker thread pool, more functions can be added later.
joneubank
left a comment
There was a problem hiding this comment.
Really great foundation for our worker setup. Love that this runs successfully. Most of my comments are for dealing with configuration and setup issue edge cases. There's a few changes to look at for server stability and completeness.
packages/data-provider/src/services/submission/submissionProcessor.ts
Outdated
Show resolved
Hide resolved
packages/data-provider/src/services/submission/submissionService.ts
Outdated
Show resolved
Hide resolved
packages/data-provider/src/services/submission/submissionService.ts
Outdated
Show resolved
Hide resolved
packages/data-provider/src/services/submission/submissionService.ts
Outdated
Show resolved
Hide resolved
| // Reset the submission status back to VALID so it can be retried | ||
| await submissionRepo.update(submissionId, { status: SUBMISSION_STATUS.VALID, updatedBy: username }); | ||
| throw error; |
There was a problem hiding this comment.
When an error occurs during committing a submission, it is back to VALID status.
| * @param configData The application configuration | ||
| * @returns The worker functions to execute tasks in the worker pool | ||
| */ | ||
| export const createWorkerPool = (configData: AppConfig): WorkerFunctions => { |
There was a problem hiding this comment.
This is the main function used to initialize the worker pool, it is used when the Lyric provider is created, returns the functions available in the baseDependency in the provider.
If any error occurs during worker pool initialization an error is thrown immediately that stops the application
joneubank
left a comment
There was a problem hiding this comment.
Amazing. Almost there. We added the shutdown mechanism, but now we need to use it in our sever and our docs.
There was a problem hiding this comment.
great documentation updates, will be very helpful. much appreciated.
| terminate: async (): Promise<void> => { | ||
| await pool.terminate(); | ||
| logger.info(LOG_MODULE, 'Worker pool terminated'); | ||
| }, |
There was a problem hiding this comment.
We should make sure this is used in our lyric server code. We should also update the documentation in the lyric provider README so that we show how to perform clean up properly.
There was a problem hiding this comment.
added in the Server a call to this function to gracefully terminate the workers.
Docs have been updated to explain the usage.
joneubank
left a comment
There was a problem hiding this comment.
Couple more comments on error handling. No requests for change, use your best judgement of whats necessary.
| .then(() => logger.info(LOG_MODULE, `Worker pool execution succeeded for submission ${submissionId}`)) | ||
| .catch((error) => { | ||
| logger.error(LOG_MODULE, `Worker pool execution failed for submission ${submissionId}: ${error}`); | ||
| throw new InternalServerError(`Commit submission failed: ${error}`); |
There was a problem hiding this comment.
How are errors thrown from the worker pool functions handled? Is there a built in handler for errors thrown from workers? At a glance it seems like this won't be caught or handled by anything (may even crash the server).
There was a problem hiding this comment.
This throw indeed is crashing the server, will remove the then and catch from here as it's already handled by the worker when if fails or succeds.
Adittionally, The worker should not trhow any error.
| message, | ||
| ); | ||
| logger.error(error); | ||
| throw new Error(`${message}`, { cause: error }); |
There was a problem hiding this comment.
Any reason to throw a generic Error instead of just throwing the original error?
| throw new Error(`${message}`, { cause: error }); | |
| throw error; |
There was a problem hiding this comment.
changed to re throw the original error!
|
PR updated. ready for code review :) |
Summary
This PR improves the performance of the submission commit process.
Issues
Description of Changes
Database changes
submission,submitted_dataandaudit_submitted_datato improve data lookupCOMMITTING, to indicate a submission is being processed from statusVALIDtoCOMMITTEDWorker threads