feat: coderabbit suggestion

This commit is contained in:
Eli Bosley
2025-01-29 13:08:41 -05:00
parent 097415f6b8
commit 3cc3f27dae

View File

@@ -13,12 +13,20 @@ export class LogRotateService {
@Cron('0 * * * *') @Cron('0 * * * *')
async handleCron() { async handleCron() {
try { try {
if (existsSync(this.logRotatePath)) { if (!existsSync(this.logRotatePath)) {
this.logger.debug('Running logrotate'); throw new Error(`Logrotate binary not found at ${this.logRotatePath}`);
await execa(`/usr/sbin/logrotate`, ['/etc/logrotate.conf']);
} }
if (!existsSync(this.configPath)) {
throw new Error(`Logrotate config not found at ${this.configPath}`);
}
this.logger.debug('Running logrotate');
const result = await execa(this.logRotatePath, [this.configPath]);
if (result.failed) {
throw new Error(`Logrotate execution failed: ${result.stderr}`);
}
this.logger.debug('Logrotate completed successfully');
} catch (error) { } catch (error) {
this.logger.error(error); this.logger.debug('Failed to run logrotate with error' + error);
} }
} }
} }