From 641fc93a496d7e13776a539397e1c9d81e441d37 Mon Sep 17 00:00:00 2001 From: Jan Kuri Date: Sun, 30 Jul 2017 09:29:00 +0200 Subject: [PATCH] fix(builds): fix build statuses and times --- .../app-builds/app-builds.component.ts | 86 +++++++++--------- .../app-repository.component.ts | 87 ++++++++++--------- 2 files changed, 89 insertions(+), 84 deletions(-) diff --git a/src/app/components/app-builds/app-builds.component.ts b/src/app/components/app-builds/app-builds.component.ts index dccadf73a..39fe93729 100644 --- a/src/app/components/app-builds/app-builds.component.ts +++ b/src/app/components/app-builds/app-builds.component.ts @@ -27,50 +27,52 @@ export class AppBuildsComponent implements OnInit, OnDestroy { ngOnInit() { this.fetch(); - this.sub = this.socketService.outputEvents.skip(1).subscribe(event => { - if (!this.builds || !event.data) { - return; - } - - if (event.type === 'buildRestarted' || event.type === 'buildStopped') { - const buildIndex = this.builds.findIndex(build => build.id === event.data); - this.builds[buildIndex].processingRequest = false; - } - - if (event.data === 'jobAdded') { - this.fetch(); - } - - const index = this.builds.findIndex(build => build.id === event.build_id); - if (index !== -1) { - const jobIndex = this.builds[index].jobs.findIndex(job => job.id === event.job_id); - if (jobIndex !== -1) { - let status = null; - switch (event.data) { - case 'jobSucceded': - status = 'success'; - break; - case 'jobQueued': - status = 'queued'; - break; - case 'jobStarted': - status = 'running'; - this.builds[index].jobs[jobIndex].start_time = new Date(); - break; - case 'jobFailed': - status = 'failed'; - this.builds[index].jobs[jobIndex].end_time = new Date(); - break; - case 'jobStopped': - status = 'failed'; - this.builds[index].jobs[jobIndex].end_time = new Date(); - break; - } + this.sub = this.socketService.outputEvents + .filter(x => x.type !== 'data') + .subscribe(event => { + if (!this.builds || !event.data) { + return; + } - this.builds[index].jobs[jobIndex].status = status; + if (event.type === 'buildRestarted' || event.type === 'buildStopped') { + const buildIndex = this.builds.findIndex(build => build.id === event.data); + this.builds[buildIndex].processingRequest = false; } - } - }); + + if (event.data === 'jobAdded') { + this.fetch(); + } + + const index = this.builds.findIndex(build => build.id === event.build_id); + if (index !== -1) { + const jobIndex = this.builds[index].jobs.findIndex(job => job.id === event.job_id); + if (jobIndex !== -1) { + let status = null; + switch (event.data) { + case 'jobSucceded': + status = 'success'; + break; + case 'jobQueued': + status = 'queued'; + break; + case 'jobStarted': + status = 'running'; + this.builds[index].jobs[jobIndex].start_time = new Date(); + break; + case 'jobFailed': + status = 'failed'; + this.builds[index].jobs[jobIndex].end_time = new Date(); + break; + case 'jobStopped': + status = 'failed'; + this.builds[index].jobs[jobIndex].end_time = new Date(); + break; + } + + this.builds[index].jobs[jobIndex].status = status; + } + } + }); } ngOnDestroy() { diff --git a/src/app/components/app-repository/app-repository.component.ts b/src/app/components/app-repository/app-repository.component.ts index d1f693648..fb2cd24f7 100644 --- a/src/app/components/app-repository/app-repository.component.ts +++ b/src/app/components/app-repository/app-repository.component.ts @@ -38,53 +38,56 @@ export class AppRepositoryComponent implements OnInit, OnDestroy { } }); - this.sub = this.socketService.outputEvents.subscribe(event => { - if (!this.repo || !event.data) { - return; - } + this.sub = this.socketService.outputEvents + .filter(x => x.type !== 'data') + .subscribe(event => { + if (!this.repo || !event.data) { + return; + } - if (event.type === 'buildRestarted' || event.type === 'buildStopped') { - const buildIndex = this.repo.builds.findIndex(build => build.id === event.data); - this.repo.builds[buildIndex].processingRequest = false; - } + if (event.type === 'buildRestarted' || event.type === 'buildStopped') { + const buildIndex = this.repo.builds.findIndex(build => build.id === event.data); + this.repo.builds[buildIndex].processingRequest = false; + } - if (event.data === 'jobAdded') { - this.fetch(); - } + if (event.data === 'jobAdded') { + this.fetch(); + } - const index = this.repo.builds.findIndex(build => build.id === event.build_id); - if (index !== -1) { - const jobIndex = this.repo.builds[index].jobs.findIndex(job => job.id === event.job_id); - if (jobIndex !== -1) { - let status = null; - switch (event.data) { - case 'jobSucceded': - status = 'success'; - break; - case 'jobQueued': - status = 'queued'; - break; - case 'jobStarted': - status = 'running'; - this.repo.builds[index].jobs[jobIndex].start_time = new Date(); - break; - case 'jobFailed': - status = 'failed'; - this.repo.builds[index].jobs[jobIndex].start_time = new Date(); - break; - case 'jobStopped': - status = 'failed'; - this.repo.builds[index].jobs[jobIndex].start_time = new Date(); - break; + const index = this.repo.builds.findIndex(build => build.id === event.build_id); + if (index !== -1) { + const jobIndex = this.repo.builds[index].jobs.findIndex(job => job.id === event.job_id); + if (jobIndex !== -1) { + let status = null; + switch (event.data) { + case 'jobSucceded': + status = 'success'; + this.repo.builds[index].jobs[jobIndex].end_time = new Date(); + break; + case 'jobQueued': + status = 'queued'; + break; + case 'jobStarted': + status = 'running'; + this.repo.builds[index].jobs[jobIndex].start_time = new Date(); + break; + case 'jobFailed': + status = 'failed'; + this.repo.builds[index].jobs[jobIndex].start_time = new Date(); + break; + case 'jobStopped': + status = 'failed'; + this.repo.builds[index].jobs[jobIndex].end_time = new Date(); + break; + } + + this.repo.builds[index].jobs[jobIndex].status = status; + + this.statusBadge = ''; + this.statusBadge = this.url + '/api/repositories/badge/' + this.id; } - - this.repo.builds[index].jobs[jobIndex].status = status; - - this.statusBadge = ''; - this.statusBadge = this.url + '/api/repositories/badge/' + this.id; } - } - }); + }); } ngOnDestroy() {