Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add run info #44

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/api/src/runs/run.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Column, CreateDateColumn, Entity, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
import { RunStatus, TaskPriority, Run, DateUtil, RunParameters } from '@tskmgr/common';
import { RunStatus, TaskPriority, Run, DateUtil, RunParameters, RunInfo } from '@tskmgr/common';
import { FileEntity } from '../files/file.entity';
import { TaskEntity } from '../tasks/task.entity';

Expand Down Expand Up @@ -29,6 +29,9 @@ export class RunEntity implements Run {
@Column({ type: 'simple-array', default: TaskPriority.Longest })
prioritization: TaskPriority[];

@Column({ type: 'jsonb', nullable: true })
info: RunInfo;

@Column({ type: 'jsonb', nullable: true })
parameters: RunParameters;

Expand Down
5 changes: 5 additions & 0 deletions apps/api/src/runs/runs.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ describe('RunsController', () => {
const run1 = await runsController.createRun({
name: `run1-${affinityId}`,
type: 'test',
url: 'http://affinity-run',
affinity: true,
info: {
url1: 'http://url1',
url2: 'http://url2',
},
parameters: {
affinityId,
},
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/runs/runs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class RunsService {
name: createRunDto.name,
type: createRunDto.type,
url: createRunDto.url,
info: createRunDto.info,
parameters: createRunDto.parameters,
prioritization: createRunDto.prioritization,
affinity: createRunDto.affinity,
Expand Down
5 changes: 3 additions & 2 deletions apps/frontend/src/app/common/tskmgr-common.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { RouterLinkActive, RouterLinkWithHref } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
import { CamelCaseToWordsPipe } from './camel-case.pipe';
import { UrlifyPipe } from './urlify.pipe';

@NgModule({
declarations: [HeaderComponent, SettingsComponent, CamelCaseToWordsPipe],
exports: [HeaderComponent, SettingsComponent, CamelCaseToWordsPipe],
declarations: [HeaderComponent, SettingsComponent, CamelCaseToWordsPipe, UrlifyPipe],
exports: [HeaderComponent, SettingsComponent, CamelCaseToWordsPipe, UrlifyPipe],
imports: [
CommonModule, //
RouterLinkWithHref,
Expand Down
23 changes: 23 additions & 0 deletions apps/frontend/src/app/common/urlify.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'urlify',
})
export class UrlifyPipe implements PipeTransform {
transform(value: string): string {
if (this.isValidURL(value)) {
return `<a target="_blank" href="${value}">${value}</a>`;
}

return value;
}

isValidURL(value: string) {
try {
new URL(value);
} catch (_) {
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { Run } from '@tskmgr/common';
template: `
<div class="d-flex flex-column w-100 m-3">
<div class="accordion" id="accordionExample">
<!-- DETAILS -->
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
<h2 class="accordion-header">
<button
class="accordion-button"
type="button"
Expand All @@ -17,7 +18,7 @@ import { Run } from '@tskmgr/common';
aria-expanded="true"
aria-controls="collapseOne"
>
Run information
Run details
</button>
</h2>
<div
Expand All @@ -29,17 +30,18 @@ import { Run } from '@tskmgr/common';
<div class="accordion-body">
<table class="table">
<tbody>
<tr *ngFor="let info of infoEntries; let i = index">
<th scope="row">{{ info.key | camelCaseToWords }}</th>
<td>{{ info.value }}</td>
<tr *ngFor="let detail of detailsEntries; let i = index">
<th scope="row">{{ detail.key | camelCaseToWords }}</th>
<td><span [outerHTML]="detail.value | urlify"></span></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingTwo">
<!-- INFO -->
<div class="accordion-item" *ngIf="infoEntries.length > 0">
<h2 class="accordion-header">
<button
class="accordion-button collapsed"
type="button"
Expand All @@ -48,7 +50,7 @@ import { Run } from '@tskmgr/common';
aria-expanded="false"
aria-controls="collapseTwo"
>
Run parameters
Run info
</button>
</h2>
<div
Expand All @@ -60,7 +62,39 @@ import { Run } from '@tskmgr/common';
<div class="accordion-body">
<table class="table">
<tbody>
<tr *ngFor="let param of paramEntries; let i = index">
<tr *ngFor="let info of infoEntries; let i = index">
<th scope="row">{{ info.key }}</th>
<td><span [outerHTML]="info.value | urlify"></span></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- PARAMETERS -->
<div class="accordion-item" *ngIf="paramsEntries.length > 0">
<h2 class="accordion-header" id="headingThree">
<button
class="accordion-button collapsed"
type="button"
data-bs-toggle="collapse"
data-bs-target="#collapseThree"
aria-expanded="false"
aria-controls="collapseThree"
>
Run parameters
</button>
</h2>
<div
id="collapseThree"
class="accordion-collapse collapse"
aria-labelledby="headingThree"
data-bs-parent="#accordionExample"
>
<div class="accordion-body">
<table class="table">
<tbody>
<tr *ngFor="let param of paramsEntries; let i = index">
<th scope="row">{{ param.key }}</th>
<td>{{ param.value }}</td>
</tr>
Expand All @@ -82,8 +116,9 @@ import { Run } from '@tskmgr/common';
],
})
export class RunDetailsDetailsComponent implements OnInit, OnDestroy {
detailsEntries: { key: string; value: string }[] = [];
infoEntries: { key: string; value: string }[] = [];
paramEntries: { key: string; value: never }[] = [];
paramsEntries: { key: string; value: never }[] = [];
run: Run;

readonly destroy$ = new Subject<void>();
Expand All @@ -93,7 +128,8 @@ export class RunDetailsDetailsComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this.runDetailsService.run$.pipe(takeUntil(this.destroy$)).subscribe((x) => {
this.run = x;
this.setInformation(x);
this.setDetails(x);
this.setInfo(x);
this.setParameters(x);
});
}
Expand All @@ -103,16 +139,29 @@ export class RunDetailsDetailsComponent implements OnInit, OnDestroy {
this.destroy$.complete();
}

private setInformation(run: Run): void {
this.infoEntries = [];
private setDetails(run: Run): void {
this.detailsEntries = [];
Object.entries(run).forEach((x) => {
const key = x[0];
const value = x[1];

if (key === 'parameters') {
if (key === 'parameters' || key == 'info') {
return;
}

this.detailsEntries.push({ key, value });
});
}

private setInfo(run: Run): void {
if (!run.info) {
return;
}

this.infoEntries = [];
const keys = Object.keys(run.info);
keys.forEach((key) => {
const value = run.info[key];
this.infoEntries.push({ key, value });
});
}
Expand All @@ -122,11 +171,11 @@ export class RunDetailsDetailsComponent implements OnInit, OnDestroy {
return;
}

this.paramEntries = [];
this.paramsEntries = [];
const keys = Object.keys(run.parameters);
keys.forEach((key) => {
const value = run.parameters[key];
this.paramEntries.push({ key, value });
this.paramsEntries.push({ key, value });
});
}
}
1 change: 1 addition & 0 deletions libs/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from './lib/runs/dto/set-leader-request.dto';
export * from './lib/runs/dto/set-leader-response.dto';
export * from './lib/runs/run-status';
export * from './lib/runs/run-parameters';
export * from './lib/runs/run-info';

// tasks
export * from './lib/tasks/task';
Expand Down
1 change: 1 addition & 0 deletions libs/common/src/lib/runs/dto/create-run-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export class CreateRunRequestDto {
readonly name: string;
readonly type: string;
readonly url?: string;
readonly info?: object;
readonly parameters?: object;
readonly prioritization?: TaskPriority[];
/** affinity will try to reschedule task on previous runner id from matching run */
Expand Down
3 changes: 3 additions & 0 deletions libs/common/src/lib/runs/run-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class RunInfo {
[key: string]: never;
}
2 changes: 2 additions & 0 deletions libs/common/src/lib/runs/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { TaskPriority } from '../tasks/task-priority';
import { Task } from '../tasks/task';
import { File } from '../files/file';
import { RunParameters } from './run-parameters';
import { RunInfo } from './run-info';

export interface Run {
id: number;
Expand All @@ -14,6 +15,7 @@ export interface Run {
leaderId: string;
affinity: boolean;
failFast: boolean;
info: RunInfo;
parameters: RunParameters;
duration: number;
createdAt: Date;
Expand Down