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
|
import { Component, OnInit, OnDestroy } from '@angular/core'
import { NotificationsService } from 'angular2-notifications'
import { RequestSchedulersService, RequestSchedulerStatsAttributes } from '../shared'
import { RequestSchedulerStats } from '../../../../../../shared'
@Component({
selector: 'my-request-schedulers-stats',
templateUrl: './request-schedulers-stats.component.html',
styleUrls: [ './request-schedulers-stats.component.scss' ]
})
export class RequestSchedulersStatsComponent implements OnInit, OnDestroy {
statsTitles = {
requestScheduler: 'Basic request scheduler',
requestVideoEventScheduler: 'Video events request scheduler',
requestVideoQaduScheduler: 'Quick and dirty video updates request scheduler'
}
stats: RequestSchedulerStats
private intervals: { [ id: string ]: number } = {
requestScheduler: null,
requestVideoEventScheduler: null,
requestVideoQaduScheduler: null
}
private timeouts: { [ id: string ]: number } = {
requestScheduler: null,
requestVideoEventScheduler: null,
requestVideoQaduScheduler: null
}
constructor (
private notificationsService: NotificationsService,
private requestService: RequestSchedulersService
) { }
ngOnInit () {
this.getStats()
this.runIntervals()
}
ngOnDestroy () {
Object.keys(this.stats).forEach(requestSchedulerName => {
if (this.intervals[requestSchedulerName] !== null) {
window.clearInterval(this.intervals[requestSchedulerName])
}
if (this.timeouts[requestSchedulerName] !== null) {
window.clearTimeout(this.timeouts[requestSchedulerName])
}
})
}
getStats () {
this.requestService.getStats().subscribe(
stats => this.stats = stats,
err => this.notificationsService.error('Error', err)
)
}
private runIntervals () {
Object.keys(this.intervals).forEach(requestSchedulerName => {
this.intervals[requestSchedulerName] = window.setInterval(() => {
const stats: RequestSchedulerStatsAttributes = this.stats[requestSchedulerName]
stats.remainingMilliSeconds -= 1000
if (stats.remainingMilliSeconds <= 0) {
this.timeouts[requestSchedulerName] = window.setTimeout(() => this.getStats(), stats.remainingMilliSeconds + 100)
}
}, 1000)
})
}
}
|