Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import {Component, OnDestroy, OnInit} from '@angular/core';
import {Subscription} from "rxjs";
import {Job, JobQueue} from "../model/job";
import {FormControl, FormGroup, Validators} from "@angular/forms";
import {JobsService} from "../services/jobs.service";
import {debounceTime, distinctUntilChanged, map} from "rxjs/operators";
import {ActivatedRoute} from "@angular/router";
import {AlertService} from "../services/alert.service";
import {FiltersService} from "../services/filters.service";
import {faExclamationTriangle} from "@fortawesome/free-solid-svg-icons";
@Component({
selector: 'app-executions',
templateUrl: './executions.component.html',
styleUrls: ['./executions.component.scss']
})
export class ExecutionsComponent implements OnInit, OnDestroy {
public queues: Array<JobQueue>;
public statuses: Array<string>;
public jobs$: Subscription;
public jobs: Array<Job>;
public pattern: string = "";
private filters$: Subscription;
public filters: object;
public faExclamationTriangle = faExclamationTriangle;
public alertAfterDays = 14;
public formGroup: FormGroup;
public alertThresholdForm: FormGroup;
constructor(
private jobService: JobsService,
private route: ActivatedRoute,
private alertService: AlertService,
private filterService: FiltersService
) {
this.queues = this.filterService.getFilter('JOB_QUEUE');
this.statuses = this.filterService.getFilter('JOB_STATUS');
}
ngOnInit() {
this.formGroup = new FormGroup({
pattern: new FormControl()
});
this.route.queryParams.subscribe(params => {
if (params.hasOwnProperty('pattern')) {
this.pattern = params.pattern;
this.formGroup.get('pattern').setValue(params.pattern);
}
if (params.hasOwnProperty('status')) {
this.filterService.setCurrentSetting('JOB_STATUS', params.status);
}
});
this.formGroup.get('pattern').valueChanges.pipe(
debounceTime(400),
distinctUntilChanged(),
map(results => results)
).subscribe((val: string) => {
this.pattern = val;
this.getJobs();
});
this.filters$ = this.filterService.currentSettings$.subscribe((filters: object) => {
this.filters = filters;
this.getJobs();
});
this.alertThresholdForm = new FormGroup({
threshold: new FormControl(this.alertAfterDays, Validators.required)
});
this.alertThresholdForm.get('threshold').valueChanges.pipe(
debounceTime(200),
distinctUntilChanged(),
map(results => results)
).subscribe((val: number) => {
this.alertAfterDays = val;
});
}
setQueue(queue: JobQueue) {
this.filterService.setCurrentSetting('JOB_QUEUE', queue);
}
setStatus(status: string) {
this.filterService.setCurrentSetting('JOB_STATUS', status);
}
getJobs() {
if (this.jobs$) {
this.jobs$.unsubscribe();
}
this.jobs = null;
var possibleId = parseInt(this.pattern);
var id = "";
if (!isNaN(possibleId)) {
id = this.pattern;
}
const queue = this.filterService.getCurrentSetting('JOB_QUEUE');
const status = this.filterService.getCurrentSetting('JOB_STATUS');
this.alertService.info('Getting ' + queue.label + ' Jobs');
this.jobs$ = this.jobService.getJobs(queue.name, id, this.pattern, status).subscribe((j: Array<Job>) => {
if (j && j.length > 0) {
this.alertService.success(queue.label + ' jobs retrieved');
this.jobs = j;
} else {
this.jobs = [];
this.alertService.error('No ' + queue.label + ' jobs found');
}
});
}
ngOnDestroy(): void {
if (this.jobs$) {
this.jobs$.unsubscribe();
}
if (this.filters$) {
this.filters$.unsubscribe();
}
}
}