Skip to content
Snippets Groups Projects
jobspec-detail.component.ts 2.42 KiB
Newer Older
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";
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']
})
export class JobspecDetailComponent implements OnInit, OnDestroy {
  private ngUnsubscribe = new Subject();
  @Input() jobspec: JobSpec;

  public faBullseye = faBullseye;
  public faFileAlt = faFileAlt;
  public faCheckSquare = faCheckSquare;
  public faEdit = faEdit;

  public lastAction: Action;

  constructor(
    private configService: ConfigurationService,
    private jobsService: JobsService,
    private alertService: AlertService,
    private actionsService: ActionsService
  ) {
  }

  ngOnInit() {
    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;
  }

    if (this.lastAction && this.lastAction.timeSince < (1000 * 60 * 5)) {
      return false;
    }
    return this.jobspec.executions.length < 1 ||
      (!!this.jobspec.lastJob && ['ERROR', 'WAITING'].indexOf(this.jobspec.lastJob.status) > -1);
    this.alertService.info('Submitting Job...');
    this.actionsService.addAction('jobSubmittedFromSpec', this.jobspec.id);
    this.jobsService.submitJob(this.jobspec.id, this.jobspec.queueName).subscribe(response => {
        this.alertService.success('Job Submitted');
        this.actionsService.removeActionByTypeAndId('jobSubmittedFromSpec', this.jobspec.id);
        this.alertService.error('Job Submition Failed');
  ngOnDestroy() {
    this.ngUnsubscribe.next();
    this.ngUnsubscribe.complete();
  }