Skip to content

Commit

Permalink
fix(builds): fix build statuses and times
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuri authored and irmana committed Jul 30, 2017
1 parent 68b00ab commit 641fc93
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 84 deletions.
86 changes: 44 additions & 42 deletions src/app/components/app-builds/app-builds.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
87 changes: 45 additions & 42 deletions src/app/components/app-repository/app-repository.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 641fc93

Please sign in to comment.