Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
BBesrour committed Nov 26, 2024
1 parent 126b113 commit 65db0c7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ export class ProgrammingSubmissionService implements IProgrammingSubmissionServi
}

private resetQueueEstimateTimer(participationId: number) {
if (this.queueEstimateTimerSubscriptions[participationId]) {
this.queueEstimateTimerSubscriptions[participationId].unsubscribe();
}
this.queueEstimateTimerSubscriptions[participationId]?.unsubscribe();
}

/**
Expand Down Expand Up @@ -270,30 +268,16 @@ export class ProgrammingSubmissionService implements IProgrammingSubmissionServi
let buildTimingInfo: BuildTimingInfo | undefined = undefined;

if (this.isLocalCIProfile) {
if (!programmingSubmission.isProcessing && !this.didSubmissionStartProcessing(programmingSubmission.commitHash!)) {
const queueRemainingTime = this.getExpectedRemainingTimeForQueue(programmingSubmission);
if (queueRemainingTime > 0) {
this.emitQueuedSubmission(
submissionParticipationId,
this.participationIdToExerciseId.get(submissionParticipationId)!,
programmingSubmission,
);
this.startQueueEstimateTimer(
submissionParticipationId,
this.participationIdToExerciseId.get(submissionParticipationId)!,
programmingSubmission,
queueRemainingTime,
);
return;
}
const isSubmissionQueued = this.handleQueuedProgrammingSubmissions(programmingSubmission, submissionParticipationId);
if (isSubmissionQueued) {
return;
}

buildTimingInfo = this.startedProcessingCache.get(programmingSubmission.commitHash!);
this.removeSubmissionFromProcessingCache(programmingSubmission.commitHash!);
}

this.emitBuildingSubmission(submissionParticipationId, this.participationIdToExerciseId.get(submissionParticipationId)!, submission, buildTimingInfo);
// Now we start a timer, if there is no result when the timer runs out, it will notify the subscribers that no result was received and show an error.
this.startResultWaitingTimer(submissionParticipationId);
}),
)
Expand All @@ -303,6 +287,24 @@ export class ProgrammingSubmissionService implements IProgrammingSubmissionServi
}
}

private handleQueuedProgrammingSubmissions(programmingSubmission: ProgrammingSubmission, submissionParticipationId: number) {
let isSubmissionQueued = false;
if (!programmingSubmission.isProcessing && !this.didSubmissionStartProcessing(programmingSubmission.commitHash!)) {
const queueRemainingTime = this.getExpectedRemainingTimeForQueue(programmingSubmission);
if (queueRemainingTime > 0) {
this.emitQueuedSubmission(submissionParticipationId, this.participationIdToExerciseId.get(submissionParticipationId)!, programmingSubmission);
this.startQueueEstimateTimer(
submissionParticipationId,
this.participationIdToExerciseId.get(submissionParticipationId)!,
programmingSubmission,
queueRemainingTime,
);
isSubmissionQueued = true;
}
}
return isSubmissionQueued;
}

private setupWebsocketSubscriptionForSubmissionProcessing(participationId: number, exerciseId: number, personal: boolean): void {
if (!this.submissionProcessingTopicsSubscribed.get(participationId)) {
let newSubmissionTopic: string;
Expand All @@ -313,7 +315,8 @@ export class ProgrammingSubmissionService implements IProgrammingSubmissionServi
}

// Only subscribe if not subscription to same topic exists (e.g. from different participation)
if (!Array.from(this.submissionProcessingTopicsSubscribed.values()).includes(newSubmissionTopic)) {
const subscriptionOnSameTopicExists = Array.from(this.submissionProcessingTopicsSubscribed.values()).includes(newSubmissionTopic);
if (!subscriptionOnSameTopicExists) {
this.websocketService.subscribe(newSubmissionTopic);
this.websocketService
.receive(newSubmissionTopic)
Expand Down Expand Up @@ -346,7 +349,7 @@ export class ProgrammingSubmissionService implements IProgrammingSubmissionServi
this.removeSubmissionFromProcessingCache(programmingSubmission.commitHash!);
this.resetQueueEstimateTimer(submissionParticipationId);
this.emitBuildingSubmission(submissionParticipationId, exerciseId, programmingSubmission, buildTimingInfo);
// Now we start a timer, if there is no result when the timer runs out, it will notify the subscribers that no result was received and show an error.

this.startResultWaitingTimer(submissionParticipationId);
}),
)
Expand Down Expand Up @@ -889,7 +892,8 @@ export class ProgrammingSubmissionService implements IProgrammingSubmissionServi

const openSubscriptionsForTopic = [...this.submissionProcessingTopicsSubscribed.values()].filter((topic: string) => topic === submissionProcessingTopic).length;
// Only unsubscribe if no other participations are using this topic
if (openSubscriptionsForTopic === 0) {
const isParcitipationUsingTopic = openSubscriptionsForTopic !== 0;
if (!isParcitipationUsingTopic) {
this.websocketService.unsubscribe(submissionProcessingTopic);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,57 @@ export class ResultProgressBarComponent implements OnDestroy {

estimatedDurationInterval: ReturnType<typeof setInterval> | undefined;

faCircleNotch = faCircleNotch;
protected readonly faCircleNotch = faCircleNotch;

constructor() {
effect(() => {
if (!this.isBuilding() && !this.isQueued()) {
if (this.estimatedDurationInterval) {
clearInterval(this.estimatedDurationInterval);
this.estimatedDurationInterval = undefined;
}
const isBuildingOrQueued = this.cleanUpIfNotBuildingOrQueued();
if (!isBuildingOrQueued) {
return;
}

clearInterval(this.estimatedDurationInterval);
if (this.estimatedDuration() && this.estimatedRemaining()) {
if (this.isBuilding()) {
this.setupQueueProgressBarForBuild();
this.updateBuildProgressBar();
} else if (this.isQueued()) {
this.setupBuildProgressBarForQueued();
this.updateQueueProgressBar();
}
} else {
if (this.isBuilding()) {
this.setupQueueProgressBarForBuild();
this.isBuildProgressBarAnimated = false;
this.buildProgressBarValue = 100;
} else if (this.isQueued()) {
this.setupBuildProgressBarForQueued();
this.isQueueProgressBarAnimated = false;
this.queueProgressBarValue = 100;
}
this.estimatedDurationInterval = setInterval(() => {
this.alternateOpacity(this.isQueued());
}, 1000); // 1 second
}
this.updateProgressBarState();
});
}

private updateProgressBarState() {
if (this.estimatedDuration() && this.estimatedRemaining()) {
if (this.isBuilding()) {
this.setupQueueProgressBarForBuild();
this.updateBuildProgressBar();
} else if (this.isQueued()) {
this.setupBuildProgressBarForQueued();
this.updateQueueProgressBar();
}
} else {
if (this.isBuilding()) {
this.setupQueueProgressBarForBuild();
this.isBuildProgressBarAnimated = false;
this.buildProgressBarValue = 100;
} else if (this.isQueued()) {
this.setupBuildProgressBarForQueued();
this.isQueueProgressBarAnimated = false;
this.queueProgressBarValue = 100;
}
this.estimatedDurationInterval = setInterval(() => {
this.alternateOpacity(this.isQueued());
}, 1000); // 1 second
}
}

private cleanUpIfNotBuildingOrQueued() {
const isBuildingOrQueued = true;
if (!this.isBuilding() && !this.isQueued()) {
if (this.estimatedDurationInterval) {
clearInterval(this.estimatedDurationInterval);
this.estimatedDurationInterval = undefined;
}
this.isQueueProgressBarAnimated = false;
}
return isBuildingOrQueued;
}

ngOnDestroy() {
if (this.estimatedDurationInterval) {
clearInterval(this.estimatedDurationInterval);
Expand Down

0 comments on commit 65db0c7

Please sign in to comment.