Skip to content
Snippets Groups Projects
Commit 92b299f5 authored by Julian Matschinske's avatar Julian Matschinske
Browse files

Limit number of tasks that can be run at once to 3

parent cb7701b1
No related branches found
No related tags found
No related merge requests found
...@@ -41,6 +41,7 @@ export class AnalysisService { ...@@ -41,6 +41,7 @@ export class AnalysisService {
public tasks: Task[] = []; public tasks: Task[] = [];
private intervalId: any; private intervalId: any;
private canLaunchNewTask = false;
constructor(private http: HttpClient) { constructor(private http: HttpClient) {
const tokens = localStorage.getItem('tokens'); const tokens = localStorage.getItem('tokens');
...@@ -147,6 +148,19 @@ export class AnalysisService { ...@@ -147,6 +148,19 @@ export class AnalysisService {
} }
async startQuickAnalysis() { 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/`, { const resp = await this.http.post<any>(`${environment.backend}task/`, {
algorithm: 'quick', algorithm: 'quick',
target: 'drug', target: 'drug',
...@@ -171,6 +185,19 @@ export class AnalysisService { ...@@ -171,6 +185,19 @@ export class AnalysisService {
} }
async startAnalysis(algorithm, target: 'drug' | 'drug-target', parameters) { 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/`, { const resp = await this.http.post<any>(`${environment.backend}task/`, {
algorithm, algorithm,
target, target,
...@@ -203,13 +230,20 @@ export class AnalysisService { ...@@ -203,13 +230,20 @@ export class AnalysisService {
}); });
} }
public canLaunchTask(): boolean {
return this.canLaunchNewTask;
}
startWatching() { startWatching() {
const watch = async () => { const watch = async () => {
if (this.tokens.length > 0) { if (this.tokens.length > 0) {
this.tasks = await this.getTasks(); this.tasks = await this.getTasks();
let queuedOrRunningTasks = 0;
this.tasks.forEach((task) => { this.tasks.forEach((task) => {
if (this.finishedTokens.find((finishedToken) => finishedToken === task.token)) { if (!task.info.done && !task.info.failed) {
} else { queuedOrRunningTasks++;
}
if (!this.finishedTokens.find((finishedToken) => finishedToken === task.token)) {
if (task.info.done) { if (task.info.done) {
this.finishedTokens.push(task.token); this.finishedTokens.push(task.token);
this.showToast(task, 'DONE'); this.showToast(task, 'DONE');
...@@ -222,6 +256,9 @@ export class AnalysisService { ...@@ -222,6 +256,9 @@ export class AnalysisService {
} }
} }
}); });
this.canLaunchNewTask = queuedOrRunningTasks < 3;
} else {
this.canLaunchNewTask = true;
} }
}; };
watch(); watch();
......
...@@ -28,6 +28,12 @@ ...@@ -28,6 +28,12 @@
</div> </div>
</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 *ngIf="algorithm==='trustrank'">
<div class="field" *ngIf="target === 'drug'"> <div class="field" *ngIf="target === 'drug'">
<label class="label">Indirect Drugs</label> <label class="label">Indirect Drugs</label>
...@@ -136,7 +142,7 @@ ...@@ -136,7 +142,7 @@
</section> </section>
<footer class="modal-card-foot"> <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> <button (click)="close()" class="button is-rounded">Close</button>
</footer> </footer>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment