def post(self): """Handles POST requests.""" payload_proto = ( training_job_response_payload_pb2.TrainingJobResponsePayload()) payload_proto.ParseFromString(self.request.body) if not validate_job_result_message_proto(payload_proto.job_result): raise self.InvalidInputException job_id = payload_proto.job_result.job_id classifier_training_job = ( classifier_services.get_classifier_training_job_by_id(job_id)) if classifier_training_job.status == ( feconf.TRAINING_JOB_STATUS_FAILED): # Send email to admin and admin-specified email recipients. # Other email recipients are specified on admin config page. email_manager.send_job_failure_email(job_id) raise self.InternalErrorException( 'The current status of the job cannot transition to COMPLETE.') classifier_data_proto = getattr( payload_proto.job_result, payload_proto.job_result.WhichOneof('classifier_frozen_model')) classifier_services.store_classifier_data( job_id, classifier_data_proto) # Update status of the training job to 'COMPLETE'. classifier_services.mark_training_job_complete(job_id) return self.render_json({})
def post(self): """Handles POST requests.""" signature = self.payload.get('signature') message = self.payload.get('message') vm_id = self.payload.get('vm_id') if vm_id == feconf.DEFAULT_VM_ID and not constants.DEV_MODE: raise self.UnauthorizedUserException if not validate_job_result_message_dict(message): raise self.InvalidInputException if not verify_signature(message, vm_id, signature): raise self.UnauthorizedUserException job_id = message['job_id'] # The classifier data received in the payload has all floating point # values stored as strings. This is because floating point numbers # are represented differently on GAE(Oppia) and GCE(Oppia-ml). # Therefore, converting all floating point numbers to string keeps # signature consistent on both Oppia and Oppia-ml. # For more info visit: https://stackoverflow.com/q/40173295 classifier_data = ( classifier_services. convert_strings_to_float_numbers_in_classifier_data( #pylint: disable=line-too-long message['classifier_data_with_floats_stringified'])) classifier_training_job = ( classifier_services.get_classifier_training_job_by_id(job_id)) if classifier_training_job.status == ( feconf.TRAINING_JOB_STATUS_FAILED): # Send email to admin and admin-specified email recipients. # Other email recipients are specified on admin config page. email_manager.send_job_failure_email(job_id) raise self.InternalErrorException( 'The current status of the job cannot transition to COMPLETE.') try: classifier_services.store_classifier_data(job_id, classifier_data) except Exception as e: raise self.InternalErrorException(e) # Update status of the training job to 'COMPLETE'. classifier_services.mark_training_job_complete(job_id) return self.render_json({})