Refactor code execution to use async functions
This refactoring is required for Sentry tracing. It ensures that the respective functions only return as soon as a code execution finished. With this approach, we can then instrument the duration of the functions, so that Sentry spans are created as desired. Co-authored-by: Jan Graichen <jgraichen@altimos.de>
This commit is contained in:

committed by
Sebastian Serth

parent
c8609e5392
commit
86c67f3c9a
@ -114,41 +114,42 @@ CodeOceanEditorRequestForComments = {
|
||||
questionElement.prop("disabled", true);
|
||||
$('#closeAskForCommentsButton').addClass('d-none');
|
||||
|
||||
var exercise_id = editor.data('exercise-id');
|
||||
var file_id = $('.editor').data('id');
|
||||
var question = questionElement.val();
|
||||
const exercise_id = editor.data('exercise-id');
|
||||
const file_id = $('.editor').data('id');
|
||||
const question = questionElement.val();
|
||||
|
||||
var createRequestForComments = function (submission) {
|
||||
this.showSpinner($('#askForCommentsButton'));
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: Routes.request_for_comments_path(),
|
||||
data: {
|
||||
request_for_comment: {
|
||||
exercise_id: exercise_id,
|
||||
file_id: file_id,
|
||||
submission_id: submission.id,
|
||||
question: question
|
||||
}
|
||||
const submission = await this.createSubmission(cause, null).catch(this.ajaxError.bind(this));
|
||||
if (!submission) return;
|
||||
|
||||
this.showSpinner($('#askForCommentsButton'));
|
||||
|
||||
const response = await $.ajax({
|
||||
method: 'POST',
|
||||
url: Routes.request_for_comments_path(),
|
||||
data: {
|
||||
request_for_comment: {
|
||||
exercise_id: exercise_id,
|
||||
file_id: file_id,
|
||||
submission_id: submission.id,
|
||||
question: question
|
||||
}
|
||||
}).done(function() {
|
||||
// trigger a run
|
||||
this.runSubmission.call(this, submission);
|
||||
$.flash.success({text: $('#askForCommentsButton').data('message-success')});
|
||||
}.bind(this)).fail(this.ajaxError.bind(this))
|
||||
.always(function () {
|
||||
bootstrap.Modal.getInstance($('#comment-modal')).hide();
|
||||
this.hideSpinner();
|
||||
$('#question').prop("disabled", false).val('');
|
||||
$('#closeAskForCommentsButton').removeClass('d-none');
|
||||
$('#askForCommentsButton').one('click', this.requestComments.bind(this));
|
||||
}.bind(this));
|
||||
};
|
||||
}
|
||||
}).catch(this.ajaxError.bind(this));
|
||||
|
||||
bootstrap.Modal.getInstance($('#comment-modal')).hide();
|
||||
this.hideSpinner();
|
||||
$('#question').prop("disabled", false).val('');
|
||||
$('#closeAskForCommentsButton').removeClass('d-none');
|
||||
$('#askForCommentsButton').one('click', this.requestComments.bind(this));
|
||||
|
||||
this.createSubmission(cause, null, createRequestForComments.bind(this));
|
||||
// we disabled the button to prevent that the user spams RFCs, but decided against this now.
|
||||
//var button = $('#requestComments');
|
||||
//button.prop('disabled', true);
|
||||
|
||||
if (response) {
|
||||
await this.runSubmission(submission);
|
||||
$.flash.success({text: $('#askForCommentsButton').data('message-success')});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user