/
archiver.service.ts
36 lines (32 loc) · 1.16 KB
/
archiver.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Injectable, Logger } from '@nestjs/common';
import { SimulationRunService } from '@biosimulations/api-nest-client';
import { catchError } from 'rxjs/operators';
import { of } from 'rxjs';
import { SshService } from '../services/ssh/ssh.service';
@Injectable()
export class ArchiverService {
private logger = new Logger('ArchiverService');
public constructor(
private sshService: SshService,
private service: SimulationRunService,
) {}
// TODO include the output archive in the files endpoint and get size from there
public async updateResultsSize(id: string): Promise<void> {
const path = this.sshService.getSSHJobDirectory(id);
const archive = `${path}/${id}.zip`;
const command = `du -b ${archive} | cut -f1`;
this.sshService.execStringCommand(command).then((output) => {
this.service
.updateSimulationRunResultsSize(id, parseInt(output.stdout))
.pipe(
catchError((err, caught) => {
this.logger.error(
`The results size for simulation run '${id}' could not be updated: ${err}`,
);
return of(null);
}),
)
.subscribe();
});
}
}