X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Badmin%2Frequests%2Frequest-stats%2Frequest-stats.component.ts;h=cca4926cf237c901bb8a8e35910cf53223ef8c18;hb=df98563e2104b82b119c00a3cd83cd0dc1242d25;hp=23b8367792329efe36696bbb38480a36c93bf622;hpb=b99290b1d5d736083513fb8f66e91f61bfe07e0b;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+admin/requests/request-stats/request-stats.component.ts b/client/src/app/+admin/requests/request-stats/request-stats.component.ts index 23b836779..cca4926cf 100644 --- a/client/src/app/+admin/requests/request-stats/request-stats.component.ts +++ b/client/src/app/+admin/requests/request-stats/request-stats.component.ts @@ -1,48 +1,80 @@ -import { setInterval } from 'timers' -import { Component, OnInit, OnDestroy } from '@angular/core'; +import { Component, OnInit, OnDestroy } from '@angular/core' -import { RequestService, RequestStats } from '../shared'; +import { NotificationsService } from 'angular2-notifications' + +import { RequestService, RequestStats } from '../shared' @Component({ - selector: 'my-request-stats', - templateUrl: './request-stats.component.html', + selector: 'my-request-stats', + templateUrl: './request-stats.component.html', styleUrls: [ './request-stats.component.scss' ] }) export class RequestStatsComponent implements OnInit, OnDestroy { - stats: RequestStats = null; - - private interval: NodeJS.Timer = null; + statsTitles = { + requestScheduler: 'Basic request scheduler', + requestVideoEventScheduler: 'Video events request scheduler', + requestVideoQaduScheduler: 'Quick and dirty video updates request scheduler' + } - constructor(private requestService: RequestService) { } + stats: { [ id: string ]: RequestStats } = { + requestScheduler: null, + requestVideoEventScheduler: null, + requestVideoQaduScheduler: null + } - ngOnInit() { - this.getStats(); - this.runInterval(); + private intervals: { [ id: string ]: number } = { + requestScheduler: null, + requestVideoEventScheduler: null, + requestVideoQaduScheduler: null } - ngOnDestroy() { - if (this.stats !== null && this.stats.secondsInterval !== null) { - clearInterval(this.interval); - } + private timeouts: { [ id: string ]: number } = { + requestScheduler: null, + requestVideoEventScheduler: null, + requestVideoQaduScheduler: null } - getStats() { - this.requestService.getStats().subscribe( - stats => this.stats = stats, + constructor ( + private notificationsService: NotificationsService, + private requestService: RequestService + ) { } - err => alert(err.text) - ); + ngOnInit () { + this.getStats() + this.runIntervals() } - private runInterval() { - this.interval = setInterval(() => { - this.stats.remainingMilliSeconds -= 1000; + ngOnDestroy () { + Object.keys(this.stats).forEach(requestSchedulerName => { + if (this.intervals[requestSchedulerName] !== null) { + window.clearInterval(this.intervals[requestSchedulerName]) + } - if (this.stats.remainingMilliSeconds <= 0) { - setTimeout(() => this.getStats(), this.stats.remainingMilliSeconds + 100); + if (this.timeouts[requestSchedulerName] !== null) { + window.clearTimeout(this.timeouts[requestSchedulerName]) } - }, 1000); + }) } + getStats () { + this.requestService.getStats().subscribe( + stats => this.stats = stats, + + err => this.notificationsService.error('Error', err.text) + ) + } + private runIntervals () { + Object.keys(this.intervals).forEach(requestSchedulerName => { + this.intervals[requestSchedulerName] = window.setInterval(() => { + const stats = this.stats[requestSchedulerName] + + stats.remainingMilliSeconds -= 1000 + + if (stats.remainingMilliSeconds <= 0) { + this.timeouts[requestSchedulerName] = window.setTimeout(() => this.getStats(), stats.remainingMilliSeconds + 100) + } + }, 1000) + }) + } }