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

And/generate certificate based on rten request #187

Merged
merged 4 commits into from
Jul 8, 2024

Conversation

andrey-canon
Copy link
Collaborator

@andrey-canon andrey-canon commented Jul 4, 2024

Description

This implements a new backend in the result notification view with new pipeline steps that allow to create a new certificate

Testing instructions

  1. set the setting ENABLE_CERTIFICATE_PUBLISHER, this will enable the result notification pipeline and the external certificate publisher, its not necessary to test the external call so you can use an invalid mode, or if you want to test the external call set CERTIFICATE_PUBLISHER_VALID_MODES with the desired mode
  2. Make a postman call with the following data
{
   "eventType":"RESULT_AVAILABLE",
   "eventTime":"?",
   "candidate":{
      "candidateName":{
         "firstName":"Maximo",
         "lastName":"Tercero"
      },
      "email":"?",
      "lastUpdate":"?",
      "vueCandidateID":"?",
      "clientCandidateID":"?"
   },
   "attempt":"$",
   "authorization":{
        "clientAuthorizationID": "1000-3000"
   },
   "exams":{
      "exam":[
         {
            "examDefinition":{
               "examSeriesCode":"?",
               "examLanguageCode":"?",
               "examName":"?",
               "deliveryModel":"?",
               "vueExamVersionId":"?",
               "vueExamRevisionID":"?",
               "clientExamVersionId":"?",
               "examForm":"?",
               "isBetaVersion":"#"
            },
            "examResult":{
               "outcomeType":"?",
               "startTime":"?",
               "timeUsed":"$",
               "passingScore":"0.8",
               "score":"0.832",
               "rawScore":"$",
               "grade":"0.5",
               "correct":"$",
               "incorrect":"$",
               "skipped":"$",
               "unscored":"$"
            },
            "noShow":"#",
            "expired":"#",
            "ndaRefused":"#",
            "deliveryEventType":"?"
         }
      ]
   },
   "vueAppointmentID":"$",
   "clientCode":"?",
   "vueCandidateID":"$",
   "clientCandidateID":"?"
}
  1. Verify that the certificate was created in /admin/certificates/generatedcertificate
  2. Check logs, if you didn't set CERTIFICATE_PUBLISHER_VALID_MODES a message with the following content must appear
    The %s certificate associated with the user <%s> and course <%s> doesn't have a valid mode and therefore its data won't be published."

Note

The whole integration can be tested by following this guide

@github-actions github-actions bot added the test label Jul 4, 2024
@github-actions github-actions bot added the size/m m lines label label Jul 4, 2024

if response.status_code == status.HTTP_200_OK and getattr(settings, "ENABLE_CERTIFICATE_PUBLISHER", False):
result_notification = ResultNotificationBackend(request_data=request.data)
result_notification.run_pipeline()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This pipeline is run in sync. Why not async?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If fails, the record would not be created in rten model

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let me answer with a question, Why async ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If fails, the record would not be created in rten model

yes, probably the generics drf views implement an atomic block, but the result will be stored if that fails due to pearson exceptions that are handled by the ErrorRealTimeImportHandler class

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let me answer with a question, Why async ?

Because in that case you isolate the RTEN request process from the generated certificate process.
You could avoid some 500 error codes, and maybe the client(Pearson) would think why we are getting 500...
All code related to the pipeline running in sync could make the request slower or fails and I think the Pearson Client is not aware that it is not related with the purpose of data sent...

Copy link
Collaborator Author

@andrey-canon andrey-canon Jul 5, 2024

Choose a reason for hiding this comment

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

Errors should never pass silently. Python zen
To avoid errors I can use a simple try except but I want that the client get a 500 error it's the only way to know that something is happening
request slower, yes, every line that you add in code affects the time response and when the code that you add is too much or needs a lot of time to be executed , one option is an async task, so is this that case ? have you experimented a slow response ? or have you identified a pipeline step that needs a lot of time ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

errors would happen in the sync or async context. Anyway sentry would report both envs. So it wouldn't pass silently meanwhile sentry is working xD.
The point is who reports the error: the worker or the lms pod. And also who is being affected by that...

Anyway, if you consider is ok I could accept that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The issue isn't about what reports the errors; it's about who receives them. On one hand, we have the client using the service, and on the other, we have the Sentry service that goes unchecked until the client complains.

Finally, t main purpose of the async tasks is to execute heavy processes, not to avoid exceptions. For that, you can catch the exceptions and use a simple log.error if you want to report it to Sentry.

dict: A dictionary containing extracted data including exam result, client authorization ID,
enrollment ID, anonymous user model ID, and anonymous user ID.
"""
client_authorization_id = request_data["authorization"]["clientAuthorizationID"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you going to handle key error with pearsonvue exceptions?? or could be other PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the reminder, I will implement that in this PR


Returns:
dict: A dictionary containing the enrollment object if found, otherwise an empty dictionary.
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add the block code:

if not enrollment:

In order to not be concerned it is first
get_enrollment_from_anonymous_user_id or get_enrollment_from_id

@github-actions github-actions bot added size/l and removed size/m m lines label labels Jul 5, 2024
Copy link
Collaborator

@johanseto johanseto left a comment

Choose a reason for hiding this comment

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

Tested and working in my local env.
2024-07-08_15-31
2024-07-08_15-31_1

Also audit is managing nice the errors.
2024-07-08_15-18

2024-07-08_15-44

@andrey-canon andrey-canon merged commit 65c41a0 into master Jul 8, 2024
7 checks passed
@andrey-canon andrey-canon deleted the and/generate_certificate_based_on_rten_request branch July 16, 2024 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants