Skip to content

Commit

Permalink
fix: ensure log files are zipped before deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
biersoeckli committed Feb 1, 2025
1 parent 8415f6b commit 6ca354e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/server/services/standalone-services/app-logs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import path from "path";
import { create } from 'tar'
import scheduleService from "./schedule.service";
import { DownloadableAppLogsModel } from "../../../shared/model/downloadable-app-logs.model";
import { CommandExecutorUtils } from "../../../server/utils/command-executor.utils";

class AppLogsService {

Expand Down Expand Up @@ -124,11 +125,20 @@ class AppLogsService {
// create tar.gz file from all log files
const logFilePath = PathUtils.appLogsFile(app.id, startOfDay);
await FsUtils.deleteFileIfExists(logFilePath); // delete existing log file --> new one will be created

/*
// this doesn't work, because it doesn't wait for the file to be written
await create({
gzip: true,
file: logFilePath,
cwd: PathUtils.appLogsFolder(app.id)
}, logPathsWritten);
*/

await CommandExecutorUtils.runCommand(`tar -czf ${logFilePath} ${logPathsWritten.join(' ')}`);
if (!FsUtils.fileExists(logFilePath)) {
throw new Error(`Error creating tar file for logs of app ${app.id} on path ${logFilePath}`);
}

for (const logPath of logPathsWritten) {
await FsUtils.deleteFileIfExists(logPath);
Expand Down

0 comments on commit 6ca354e

Please sign in to comment.