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

#4354 - Change Request Revamp - 1st effort - Warping up workflow during "in-progress" application #4491

Merged

Conversation

andrewsignori-aot
Copy link
Collaborator

@andrewsignori-aot andrewsignori-aot commented Mar 18, 2025

  • Created a variation for the existing worker "workflow-wrap-up" to allow its usage before the "end workflow" for the assessment-gateway "Applications In Progress" lane, as shown in items 1 to 3 in the below image (image 4 is working as before).
    • The worker is backward compatible with the existing workflow, which means that once deployed, workflows executing the previous version where the new header is not provided will be able to finish its process as before. The absence of the header makes it works as before.
    • Note: fixed an issue when a job.complete() was returned from inside a transaction block with the intention of finishing the worker task but was actually finishing only the transaction block, leaving the rest of the worker processing to still be executed.

image

The workflow task now accepts a header to define its behavior, as shown below.

image

image

@andrewsignori-aot andrewsignori-aot self-assigned this Mar 18, 2025
@andrewsignori-aot andrewsignori-aot added Camunda Workers Camunda Worflow Involves camunda workflow changes labels Mar 18, 2025
@andrewsignori-aot andrewsignori-aot marked this pull request as ready for review March 18, 2025 16:24
@andrewsignori-aot andrewsignori-aot changed the title #4431 - Student View change request revamp - Warping up workflow during "in-progress" application #4454 - Change Request Revamp - 1st effort - Warping up workflow during "in-progress" application Mar 18, 2025
@andrewsignori-aot andrewsignori-aot changed the title #4454 - Change Request Revamp - 1st effort - Warping up workflow during "in-progress" application #4354- Change Request Revamp - 1st effort - Warping up workflow during "in-progress" application Mar 18, 2025
@andrewsignori-aot andrewsignori-aot changed the title #4354- Change Request Revamp - 1st effort - Warping up workflow during "in-progress" application #4354 - Change Request Revamp - 1st effort - Warping up workflow during "in-progress" application Mar 18, 2025
@dheepak-aot dheepak-aot self-requested a review March 18, 2025 19:41
* @param workflowData workflow data.
* @param options customize the payload.
* - `workflowData` workflow data.
* - `wrapUpType` wrap-up type, default {@link WorkflowWrapUpType.CompleteWrapUp} if not provided.
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

const studentAssessment = await studentAssessmentRepo.findOne({
select: { studentAssessmentStatus: true, workflowData: true as unknown },
select: { studentAssessmentStatus: true },
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not part of the PR. But selecting id here would make the query(sql) better as we have observed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just to ensure that we are on the same page, related to SQL/DB, the query is better without the ID since it is not required.
From Typeorm's perspective, it may fail for child objects when the parent does not have a single property as part of the select, and that leads us to include the ID in the parent object sometimes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I meant, from what I remembered in the past if we do not select the id, typeorm was creating a SQL select with id and also the selected properties(from find/findone) and was pulling the selected properties from that query output.

I am not sure if that was the right understanding, but it looks like typeorm always uses id irrespective if it being used in select or not.

e.g.

await db.studentAssessment.findOne({
      select: { id: true, studentAssessmentStatus: true },
      where: { id: application.currentAssessment.id },
    });

results in

select
	"StudentAssessment"."student_assessment_status" as "StudentAssessment_student_assessment_status",
	"StudentAssessment"."id" as "StudentAssessment_id"
from
	"sims"."student_assessments" "StudentAssessment"
where
	(("StudentAssessment"."id" = $1))
limit 1

Comment on lines +316 to +319
if (workflowIsCancelled) {
if (!options?.workflowData) {
// No update is executed because the data was already present or the workflow was cancelled.
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

May or may not be part of the PR. But this logic should be part of the controller rather than service.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It may, but the controller is already executing too much and I was not focusing on going further in any refactoring.
The controller logic should be segregated already in at least two other methods but I have no intention to address this as part of this ticket goal 😉

@@ -261,52 +267,67 @@ export class AssessmentController {
jobLogger.error(message);
return job.error(ASSESSMENT_NOT_FOUND, message);
}
jobLogger.log(
`Workflow wrap-up type requested: ${job.customHeaders.wrapUpType}.`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the backward-compatibility is also the intention this will print null if previous version of workflow is used.

Copy link
Collaborator Author

@andrewsignori-aot andrewsignori-aot Mar 18, 2025

Choose a reason for hiding this comment

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

Yes, it will. The backward compatibility will be achieved where it matters. The workflow needs to be backward-compatible enough to allow any in-flight assessment to be finished. Any new assessment executed once this is deployed will start using the header independently if it is a change request or not.
I am not sure if it i clear but one point is the backward compatibility mentioned in the ticket that will allow assessments to be executed.
The backward compatibility mentioned in the PR description is to allow the in-flight workflows to be finalized when a worker is changed, in this case, to receive a new header.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I get the intention more precisely when the in-flight instances are mentioned. I am good here.

);
if (jobActionAcknowledgement) {
// If there is a job result to be returned, the worker should finalize its processing.
return jobActionAcknowledgement;
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

* Executes all wrap-up operations, setting the assessment status to completed and
* executing other processes related to sequential processing.
*/
CompleteWrapUp = "Complete wrap-up",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor, it could be just Complete as it belongs to wrap up type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed.

<bpmn:extensionElements>
<zeebe:taskDefinition type="workflow-wrap-up" />
<zeebe:taskHeaders>
<zeebe:header key="wrapUpType" value="Assessment status only" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

It could be a variable initialized at start of workflow and used across many places.

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do not see it as a benefit or a better approach. The headers are meant to pass parameters to influence the worker process behavior, which is exactly what we are executing here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But what is mentioned above is not about usage of headers. It is about using a value from variable instead of repeating the value. Let me know if I am missing something here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I got it now that it is related to a broader conversation about the enum usage in the workflow and a possible way to have an enum-like structure type in BPMN. I will take a look outside this PR effort. Thanks for the chat.

@dheepak-aot
Copy link
Collaborator

Great way to wrap up the workflow ends. Added few comments. Please have a look.

Copy link

E2E Workflow Workers Coverage Report

Totals Coverage
Statements: 65.81% ( 614 / 933 )
Methods: 60.36% ( 67 / 111 )
Lines: 68.87% ( 489 / 710 )
Branches: 51.79% ( 58 / 112 )

Copy link

Backend Unit Tests Coverage Report

Totals Coverage
Statements: 22.01% ( 3975 / 18063 )
Methods: 9.85% ( 228 / 2314 )
Lines: 25.4% ( 3437 / 13530 )
Branches: 13.97% ( 310 / 2219 )

Copy link

E2E Queue Consumers Coverage Report

Totals Coverage
Statements: 85.72% ( 1507 / 1758 )
Methods: 83.25% ( 169 / 203 )
Lines: 88.1% ( 1244 / 1412 )
Branches: 65.73% ( 94 / 143 )

Copy link

E2E SIMS API Coverage Report

Totals Coverage
Statements: 70.77% ( 6497 / 9181 )
Methods: 68.54% ( 806 / 1176 )
Lines: 74.32% ( 5049 / 6794 )
Branches: 53.01% ( 642 / 1211 )

Copy link
Collaborator

@dheepak-aot dheepak-aot left a comment

Choose a reason for hiding this comment

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

Thanks for making the change and discussions. Looks good 👍

Copy link
Collaborator

@sh16011993 sh16011993 left a comment

Choose a reason for hiding this comment

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

Great work @andrewsignori-aot 👍

@andrewsignori-aot andrewsignori-aot added this pull request to the merge queue Mar 19, 2025
Merged via the queue into main with commit 2685d11 Mar 19, 2025
21 checks passed
@andrewsignori-aot andrewsignori-aot deleted the feature/#4431-set-assessment-status-as-completed branch March 19, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Camunda Worflow Involves camunda workflow changes Camunda Workers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants