Skip to content

Commit

Permalink
feat: error handling (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSlimvReal committed Dec 12, 2023
1 parent 1067589 commit 9789bf3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ jobs:
tags: aamdigital/deployer-ms:latest
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
RUN_TESTS=${{ true }}
18 changes: 17 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"@sentry/node": "^7.38.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.8.0"
"rxjs": "^7.8.0",
"tail": "^2.2.6"
},
"devDependencies": {
"@nestjs/cli": "^9.2.0",
Expand All @@ -41,6 +42,7 @@
"@types/jest": "^29.4.0",
"@types/node": "^18.13.0",
"@types/supertest": "^2.0.12",
"@types/tail": "^2.2.3",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.52.0",
"eslint": "^8.34.0",
Expand Down
29 changes: 25 additions & 4 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { DeploymentInfo } from './deployment-info.dto';
import * as fs from 'fs';
import { HttpService } from '@nestjs/axios';
import { ConfigService } from '@nestjs/config';
import { catchError, map } from 'rxjs';
import { catchError, mergeMap, Observable, Subject } from 'rxjs';
import { Tail } from 'tail';

@Controller()
export class AppController {
Expand All @@ -37,11 +38,11 @@ export class AppController {
}
throw err;
}),
map(() => this.writeCommandsToPipe(deploymentInfo)),
mergeMap(() => this.writeCommandsToPipe(deploymentInfo)),
);
}

private writeCommandsToPipe(deploymentInfo: DeploymentInfo) {
private writeCommandsToPipe(deploymentInfo: DeploymentInfo): Observable<any> {
console.log('info', deploymentInfo);

if (
Expand All @@ -59,6 +60,26 @@ export class AppController {
const ws = fs.createWriteStream('dist/assets/arg-pipe');
ws.write(args);
ws.close();
return { ok: true };
return this.getResult();
}

private getResult() {
const result = new Subject();
const tail = new Tail('dist/assets/log.txt');
tail.on('line', (line: string) => {
console.log('processing line', line);
if (line.startsWith('ERROR')) {
const message = line.replace('ERROR ', '');
result.error(new BadRequestException(message));
result.complete();
tail.unwatch();
} else if (line.startsWith('DONE')) {
result.next({ ok: true });
result.complete();
tail.unwatch();
}
});

return result.asObservable();
}
}

0 comments on commit 9789bf3

Please sign in to comment.