diff --git a/src/app/analysis.service.ts b/src/app/analysis.service.ts index 1cf9ff857000a54e6a8436777e83392cab8c7648..cd137b45b705345b6f3a0f0bb76ac32c41a573f5 100644 --- a/src/app/analysis.service.ts +++ b/src/app/analysis.service.ts @@ -41,6 +41,7 @@ export class AnalysisService { public tasks: Task[] = []; private intervalId: any; + private canLaunchNewTask = false; constructor(private http: HttpClient) { const tokens = localStorage.getItem('tokens'); @@ -147,6 +148,19 @@ export class AnalysisService { } async startQuickAnalysis() { + if (!this.canLaunchTask()) { + toast({ + message: 'You can only run 3 tasks at once. Please wait for one of them to finish or delete it from the task list.', + duration: 5000, + dismissible: true, + pauseOnHover: true, + type: 'is-danger', + position: 'top-center', + animate: {in: 'fadeIn', out: 'fadeOut'} + }); + return; + } + const resp = await this.http.post<any>(`${environment.backend}task/`, { algorithm: 'quick', target: 'drug', @@ -171,6 +185,19 @@ export class AnalysisService { } async startAnalysis(algorithm, target: 'drug' | 'drug-target', parameters) { + if (!this.canLaunchTask()) { + toast({ + message: 'You can only run 3 tasks at once. Please wait for one of them to finish or delete it from the task list.', + duration: 5000, + dismissible: true, + pauseOnHover: true, + type: 'is-danger', + position: 'top-center', + animate: {in: 'fadeIn', out: 'fadeOut'} + }); + return; + } + const resp = await this.http.post<any>(`${environment.backend}task/`, { algorithm, target, @@ -203,13 +230,20 @@ export class AnalysisService { }); } + public canLaunchTask(): boolean { + return this.canLaunchNewTask; + } + startWatching() { const watch = async () => { if (this.tokens.length > 0) { this.tasks = await this.getTasks(); + let queuedOrRunningTasks = 0; this.tasks.forEach((task) => { - if (this.finishedTokens.find((finishedToken) => finishedToken === task.token)) { - } else { + if (!task.info.done && !task.info.failed) { + queuedOrRunningTasks++; + } + if (!this.finishedTokens.find((finishedToken) => finishedToken === task.token)) { if (task.info.done) { this.finishedTokens.push(task.token); this.showToast(task, 'DONE'); @@ -222,6 +256,9 @@ export class AnalysisService { } } }); + this.canLaunchNewTask = queuedOrRunningTasks < 3; + } else { + this.canLaunchNewTask = true; } }; watch(); diff --git a/src/app/components/launch-analysis/launch-analysis.component.html b/src/app/components/launch-analysis/launch-analysis.component.html index 95560e6e51753aa47b391c260a276e88e31d7843..fa30c15b84bfd1ccf864887c35284ffcf7331fbc 100644 --- a/src/app/components/launch-analysis/launch-analysis.component.html +++ b/src/app/components/launch-analysis/launch-analysis.component.html @@ -28,6 +28,12 @@ </div> </div> + <div *ngIf="!analysis.canLaunchTask()"> + <div class="notification is-warning warning"> + You can only run 3 tasks at once. Please wait for one of them to finish or delete it from the task list. + </div> + </div> + <div *ngIf="algorithm==='trustrank'"> <div class="field" *ngIf="target === 'drug'"> <label class="label">Indirect Drugs</label> @@ -136,7 +142,7 @@ </section> <footer class="modal-card-foot"> - <button (click)="startTask(); close()" class="button is-success is-rounded" [disabled]="target === 'drug' && hasBaits">Launch</button> + <button (click)="startTask(); close()" class="button is-success is-rounded" [disabled]="(target === 'drug' && hasBaits) || !analysis.canLaunchTask()">Launch</button> <button (click)="close()" class="button is-rounded">Close</button> </footer> </div>