use of org.stepik.api.objects.submissions.Submissions in project intellij-plugins by StepicOrg.
the class SendAction method checkStepStatus.
public static void checkStepStatus(@NotNull Project project, @NotNull StepikApiClient stepikApiClient, @NotNull StepNode stepNode, final long submissionId, @NotNull ProgressIndicator indicator) {
String stepIdString = "id=" + stepNode.getId();
logger.info("Started check a status for step: " + stepIdString);
String stepStatus = EVALUATION;
int timer = 0;
String hint;
indicator.setIndeterminate(false);
Submission currentSubmission = null;
while (timer < FIVE_MINUTES) {
try {
Submissions submission = stepikApiClient.submissions().get().id(submissionId).execute();
if (!submission.isEmpty()) {
currentSubmission = submission.getFirst();
ActionUtils.setupCheckProgress(indicator, currentSubmission, timer);
stepStatus = currentSubmission.getStatus();
if (!EVALUATION.equals(stepStatus)) {
break;
}
}
Thread.sleep(PERIOD);
if (Utils.isCanceled()) {
Metrics.getStepStatusAction(project, stepNode, USER_CANCELED);
return;
}
timer += PERIOD;
} catch (StepikClientException | InterruptedException e) {
ActionUtils.notifyError(project, "Error", "Get Status error");
logger.info("Stop check a status for step: " + stepIdString, e);
return;
}
}
if (currentSubmission == null) {
logger.info(String.format("Stop check a status for step: %s without result", stepIdString));
return;
}
MetricsStatus actionStatus = EVALUATION.equals(stepStatus) ? TIME_OVER : SUCCESSFUL;
Metrics.getStepStatusAction(project, stepNode, actionStatus);
indicator.setIndeterminate(true);
indicator.setText("");
hint = currentSubmission.getHint();
if (stepNode.getType() == StepType.CODE) {
notify(project, stepNode, stepStatus, hint);
}
ApplicationManager.getApplication().invokeLater(() -> {
if (!project.isDisposed()) {
ProjectView.getInstance(project).refresh();
}
StepikProjectManager.updateSelection(project);
});
logger.info(String.format("Finish check a status for step: %s with status: %s", stepIdString, stepStatus));
}
Aggregations