Newer
Older

Reid Givens
committed
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
import {JobSpec} from "../../../model/job";
import {ConfigurationService} from "../../../env/configuration.service";
import {faBullseye, faCheckSquare, faEdit, faFileAlt} from "@fortawesome/free-solid-svg-icons";
import {JobsService} from "../../../services/jobs.service";
import {AlertService} from "../../../services/alert.service";

Reid Givens
committed
import {ActionsService} from "../../../services/actions.service";
import {Subject} from "rxjs";
import {takeUntil} from "rxjs/operators";
import {Action} from "../../../model/action";
@Component({
selector: 'app-jobspec-detail',
templateUrl: './jobspec-detail.component.html',
styleUrls: ['./jobspec-detail.component.scss']
})

Reid Givens
committed
export class JobspecDetailComponent implements OnInit, OnDestroy {

Reid Givens
committed
private ngUnsubscribe = new Subject();
@Input() jobspec: JobSpec;
public faBullseye = faBullseye;
public faFileAlt = faFileAlt;
public faCheckSquare = faCheckSquare;
public faEdit = faEdit;

Reid Givens
committed
public lastAction: Action;
constructor(
private configService: ConfigurationService,
private jobsService: JobsService,
private alertService: AlertService,
private actionsService: ActionsService
) {

Reid Givens
committed
this.actionsService.actionsTaken$.pipe(takeUntil(this.ngUnsubscribe)).subscribe((actions: Array<Action>) => {
actions.forEach((a: Action) => {
if (a.type === 'jobSubmittedFromSpec' && a.id === this.jobspec.id) {
this.lastAction = a;
}
});
});
}
getConfigUrl(): string {
return this.configService.config.url;
}
canBeSubmitted(): boolean {

Reid Givens
committed
if (this.lastAction && this.lastAction.timeSince < (1000 * 60 * 5)) {
return false;
}
return this.jobspec.executions.length < 1 ||

Reid Givens
committed
(!!this.jobspec.lastJob && ['ERROR', 'WAITING'].indexOf(this.jobspec.lastJob.status) > -1);
}
submitJob(): void {
this.alertService.info('Submitting Job...');

Reid Givens
committed
this.actionsService.addAction('jobSubmittedFromSpec', this.jobspec.id);
this.jobsService.submitJob(this.jobspec.id, this.jobspec.queueName).subscribe(response => {
this.alertService.success('Job Submitted');
},
error => {

Reid Givens
committed
this.actionsService.removeActionByTypeAndId('jobSubmittedFromSpec', this.jobspec.id);
this.alertService.error('Job Submition Failed');
});
}

Reid Givens
committed
ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}