Skip to content

Commit

Permalink
feat(): list of previous build and job runs
Browse files Browse the repository at this point in the history
  • Loading branch information
Izak88 committed Aug 16, 2017
1 parent 82857e6 commit fd87f07
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 68 deletions.
34 changes: 17 additions & 17 deletions e2e/070_job.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ describe('Job Details', () => {

it('should see console log and then collapse last command output', () => {
return browser.get('/job/15')
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .command')).count().then(cnt => cnt === 6);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .output.is-hidden')).count().then(cnt => {
return cnt === 5;
});
}))
.then((): any => element.all(by.css('.terminal .command-line')).first().click())
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .command')).count().then(cnt => cnt === 6);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .output.is-hidden')).count().then(cnt => {
return cnt === 4;
});
}));
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .command')).count().then(cnt => cnt === 6);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .output.is-hidden')).count().then(cnt => {
return cnt === 5;
});
}))
.then((): any => element.all(by.css('.terminal .command-line')).first().click())
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .command')).count().then(cnt => cnt === 6);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .output.is-hidden')).count().then(cnt => {
return cnt === 4;
});
}));
});

it('should restart job watch console log until it matches expected output', () => {
Expand Down
26 changes: 14 additions & 12 deletions src/api/db/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ export function getBuilds(limit: number, offset: number): Promise<any> {

export function getBuild(id: number): Promise<any> {
return new Promise((resolve, reject) => {
new Build({ id: id }).fetch({ withRelated: ['repository', 'jobs.runs'] }).then(build => {
if (!build) {
reject();
}
new Build({ id: id }).fetch({ withRelated: ['repository', 'jobs.runs', 'runs'] })
.then(build => {
if (!build) {
reject();
}

build = build.toJSON();
build.jobs = build.jobs.map(job => {
job.end_time = job.runs[job.runs.length - 1].end_time;
job.start_time = job.runs[job.runs.length - 1].start_time;
job.status = job.runs[job.runs.length - 1].status;
return job;
});
build = build.toJSON();
build.jobs = build.jobs.map(job => {
job.end_time = job.runs[job.runs.length - 1].end_time;
job.start_time = job.runs[job.runs.length - 1].start_time;
job.status = job.runs[job.runs.length - 1].status;
return job;
});

return build;
return build;
})
.then(build => {
new BuildRun()
Expand Down Expand Up @@ -96,6 +97,7 @@ export function updateBuild(data: any): Promise<boolean> {
delete data.jobs;
delete data.repository;
delete data.lastBuild;
delete data.runs;

new Build({ id: data.id }).save(data, { method: 'update', require: false }).then(build => {
if (!build) {
Expand Down
14 changes: 0 additions & 14 deletions src/api/db/job-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,3 @@ export function updateJobRun(data: any): Promise<any> {
.then(job => resolve(job.toJSON()));
});
}

export function resetJobRun(runId: number): Promise<any> {
return new Promise((resolve, reject) => {
const data = {
start_time: new Date(),
end_time: null,
status: 'queued',
log: '',
id: runId
};

updateJobRun(data);
});
}
2 changes: 2 additions & 0 deletions src/api/db/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ export function create(): Promise<null> {
t.text('log');
t.integer('job_id').notNullable();
t.foreign('job_id').references('job.id');
t.integer('build_run_id').notNullable();
t.foreign('build_run_id').references('build_run.id');
t.timestamps();
}))
.then(() => schema.createTableIfNotExists('permissions', (t: knex.TableBuilder) => {
Expand Down
1 change: 1 addition & 0 deletions src/api/db/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ export class JobRun extends Bookshelf.Model<any> {
get tableName() { return 'job_runs'; }
get hasTimestamps() { return true; }
job() { return this.belongsTo(Job, 'job_id'); }
build_run() { return this.belongsTo(BuildRun, 'build_run_id'); }
}
79 changes: 54 additions & 25 deletions src/api/process-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,30 @@ export function startBuild(data: any): Promise<any> {
builds_id: build.id
};

return dbJob.insertJob(jobData).then(job => {
const jobRunData = {
start_time: new Date(),
end_time: null,
status: 'queued',
log: '',
job_id: job.id
};
return dbJobRuns.insertJobRun(jobRunData).then(() => {
jobEvents.next({
type: 'process',
build_id: build.id,
job_id: job.id,
data: 'jobAdded'
return dbJob.insertJob(jobData)
.then(job => {
getLastRunId(build.id).then(buildRunId => {
const jobRunData = {
start_time: new Date(),
end_time: null,
status: 'queued',
log: '',
build_run_id: buildRunId,
job_id: job.id
};

return dbJobRuns.insertJobRun(jobRunData).then(() => {
jobEvents.next({
type: 'process',
build_id: build.id,
job_id: job.id,
data: 'jobAdded'
});

return queueJob(build.id, job.id);
});
});

return queueJob(build.id, job.id);
});
});
});
}, Promise.resolve());
});
Expand Down Expand Up @@ -356,10 +361,22 @@ export function restartBuild(buildId: number): Promise<any> {

return updateBuild(build)
.then(() => {
jobs.forEach(job => {
dbJobRuns.insertJobRun(
{ start_time: new Date(), end_time: null, status: 'queued', log: '', job_id: job.id }
);
build.build_id = buildId;
delete build.repositories_id;
delete build.jobs;
insertBuildRun(build);
})
.then(() => getLastRunId(build.id))
.then(buildRunId => {
return jobs.forEach(job => {
dbJobRuns.insertJobRun({
start_time: new Date(),
end_time: null,
status: 'queued',
log: '',
build_run_id: buildRunId,
job_id: job.id
});
});
})
.then(() => {
Expand All @@ -382,8 +399,14 @@ export function stopBuild(buildId: number): Promise<any> {
export function restartJob(jobId: number): Promise<void> {
let jobData = null;
return stopJob(jobId)
.then(() => dbJobRuns.insertJobRun(
{ start_time: new Date(), end_time: null, status: 'queued', log: '', job_id: jobId }))
.then(() => dbJob.getLastRun(jobId))
.then(lastRun => dbJobRuns.insertJobRun({
start_time: new Date(),
end_time: null,
status: 'queued',
log: '',
build_run_id: lastRun.build_run_id,
job_id: jobId }))
.then(job => jobData = job)
.then(() => queueJob(jobData.builds_id, jobId))
.then(() => {
Expand All @@ -399,8 +422,14 @@ export function restartJob(jobId: number): Promise<void> {
export function restartJobWithSshAndVnc(jobId: number): Promise<void> {
let jobData = null;
return stopJob(jobId)
.then(() => dbJobRuns.insertJobRun(
{ start_time: new Date(), end_time: null, status: 'queued', log: '', job_id: jobId }))
.then(() => dbJob.getLastRun(jobId))
.then(lastRun => dbJobRuns.insertJobRun({
start_time: new Date(),
end_time: null,
status: 'queued',
log: '',
build_run_id: lastRun.build_run_id,
job_id: jobId }))
.then(job => jobData = job)
.then(() => queueJob(jobData.builds_id, jobId, true))
.then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ <h2>{{ build?.message }}</h2>
</div>
</div>
</div>
<div class="column is-12" *ngIf="build.runs && build.runs.length > 1">
<div class="build-top-container">
<div class="build-top-content">
<h1 class="bold">
<span>Previous Runs:</span>
</h1>
<hr/>
<div class="columns list-item"
*ngFor="let run of build.runs; let i = index;"
[ngClass]="{ 'is-queued': run.status === 'queued', 'is-success': run.status === 'success', 'is-running': run.status === 'running', 'is-errored': true }">
<div class="column is-4">
<span>{{ run.start_time | date:'dd MM yyyy hh:mm:ss' }} - {{ run.end_time | date:'dd MM yyyy hh:mm:ss' }}</span>
</div>
<div class="column is-8">
<span>{{ run.message }} ({{ run.sha}})</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down
17 changes: 17 additions & 0 deletions src/app/components/app-job/app-job.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ <h2>{{ job?.build?.message }}</h2>
<div class="column is-12">
<app-terminal [data]="terminalInput" (outputData)="terminalOutput($event)" [options]="terminalOptions"></app-terminal>
</div>
<div class="column is-12" *ngIf="job.runs && job.runs.length > 1">
<div class="build-top-container">
<div class="build-top-content">
<h1 class="bold">
<span>Previous Runs:</span>
</h1>
<hr/>
<div class="columns list-item"
*ngFor="let run of job.runs; let i = index;"
[ngClass]="{ 'is-queued': run.status === 'queued', 'is-success': run.status === 'success', 'is-running': run.status === 'running', 'is-errored': run.status === 'failed' }">
<div class="column is-8">
<span>{{ run.start_time | date:'dd MM yyyy hh:mm:ss' }} - {{ run.end_time | date:'dd MM yyyy hh:mm:ss' }}</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit fd87f07

Please sign in to comment.