Skip to content
Snippets Groups Projects
Commit 538cc694 authored by Julian Späth's avatar Julian Späth
Browse files

Merge branch 'restrict-no-of-tasks' into 'master'

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

See merge request covid-19/frontend!73
parents cb7701b1 92b299f5
No related branches found
No related tags found
No related merge requests found
......@@ -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();
......
......@@ -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>
......
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