bcgov / SIMS

Student Information Management System. Post-Secondary Student Financial Aid System
Apache License 2.0
24 stars 13 forks source link

Analysis to process assessments in the queue #1896

Closed JasonCTang closed 1 year ago

JasonCTang commented 1 year ago

Describe the task Analysis to trigger Camunda assessment workflows using queues. Right now, most of the time, the assessment/reassessment records are created and the call to the queue happens right away. If the queue call fails or the queue is cleared there is no other attempt to start the workflow again.

Acceptance Criteria

andrewsignori-aot commented 1 year ago

Analysis

New status for the assessment

Regular Assessment Lifecycle

For a single workflow execution, the assessments will progress as shown below.

Stage 1

The student_assessment record is saved to the database with the default Created status.

image.png

Stage 2

The record with Created status:

  1. is selected by the assessment-workflow-execution-queue scheduler.
  2. its status is updated to Queued.
  3. Its id is also set in the application's current_processing_assessment_id column.
  4. it is added to the start-application-assessment queue.

image.png

Stage 3

  1. The workflow has its execution started by Camunda.
  2. The associate-workflow-instance worker, besides setting the workflow_id in DB (already happening), also sets the workflow status to In progress.

During this stage, alongside the associate-workflow-instance execution, if another workflow was already set to process the student_assessment, use the job.cancelWorkflow(); to terminate its execution.

image.png

Stage 4

A new workflow worker is created at the end of the workflow to have the student_assessment record changed to completed.

image.png

Queued Assessment Lifecycle

On the occasion when more than one student_assessment record is created, a scheduler will coordinate their ordered execution. At any given time, assessments for one particular application can have 0 to 1 "Queued" records and 1 to n created records waiting to be processed. Every time that a student_assessment record is queued its id is also set in the application's current_processing_assessment_id column.

Stage 1

image.png image.png

Stage 2

image.png image.png

Stage 3

image.png image.png

Assessment Cancellation Lifecycle

The cancellation of a workflow is currently executed by the queue cancel-application-assessment. The Offering bulk change, for instance, executes also the bulk cancellation of any In progress application. To allow the cancellation to also be handled by the schedulers, we can use the assessment status Cancellation requested to update any student-assessment to be canceled. The scheduler can then look for these records and try to execute the process and set the student-assessment as canceled. The workflow cancellation process happen immediately and right now it is processed by cancel-application-assessment.processor.ts.

image.png

image.png

image.png

image.png

Schedulers

Assessment workflow execution (assessment-workflow-execution-queue)

Coordinate the execution of all the student_assessments to ensure its execution. Allow multiple student_assessments to be created and ensures their ordered execution and its association with the application's current assessment.

Execution interval

Executed every minute or some short interval to be discussed.

Target records

Process description

Assessment Workflow execution retry (assessment-workflow-execution-queue-retry)

Checks for any stalled Queued student_assessments that did not start after a long period.

Execution interval

Executed every few hours or some long interval to be discussed.

Target records

Any application where the current assessment is in Queued status for some long period of time (e.g. 6 hours).

Process description

Queue the assessment for execution (already existing start-application-assessment).

Refactors

Schedulers should trigger workflows

Stop triggering the start-application-assessment and the cancel-application-assessment from the applications. Only the new schedulers would be responsible for triggering the Camunda workflows and canceling them. We can consider maybe letting the "Original Assessment" trigger the assessment for a better user experience once the application is submitted.

Current points triggering the assessment workflow:

Current points for canceling the assessment workflow:

Notifications

Some assessment creations, like Scholastic Standing, also create notifications for the students. We should consider triggering these notifications when the specific assessment becomes the application's current assessment.

Other refactors