v1.0.23
This commit is contained in:
1 parent
e9a9f0ca25
commit
0bb10cabb9
42 files changed
+7147
-239
No files matched your search
@@ -20,6 +20,7 @@ import {
|
||||
export const SYSTEM_SCHEDULE_CLEANUP_ID = 1;
|
||||
export const SYSTEM_EVENT_CLEANUP_ID = 2;
|
||||
export const SYSTEM_VOLUME_HELPER_CLEANUP_ID = 3;
|
||||
export const SYSTEM_SCANNER_CLEANUP_ID = 4;
|
||||
|
||||
/**
|
||||
* Execute schedule execution cleanup job.
|
||||
@@ -200,3 +201,66 @@ export async function runVolumeHelperCleanupJob(
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute scanner cache cleanup job.
|
||||
* Removes scanner database volumes and bind mount directories to reclaim disk space.
|
||||
*/
|
||||
export async function runScannerCacheCleanupJob(
|
||||
triggeredBy: ScheduleTrigger = 'cron',
|
||||
cleanupFn?: () => Promise<{ volumes: string[]; dirs: string[] }>
|
||||
): Promise<void> {
|
||||
const startTime = Date.now();
|
||||
|
||||
const execution = await createScheduleExecution({
|
||||
scheduleType: 'system_cleanup',
|
||||
scheduleId: SYSTEM_SCANNER_CLEANUP_ID,
|
||||
environmentId: null,
|
||||
entityName: 'Scanner cache cleanup',
|
||||
triggeredBy,
|
||||
status: 'running'
|
||||
});
|
||||
|
||||
await updateScheduleExecution(execution.id, {
|
||||
startedAt: new Date().toISOString()
|
||||
});
|
||||
|
||||
const log = async (message: string) => {
|
||||
console.log(`[Scanner Cache Cleanup] ${message}`);
|
||||
await appendScheduleExecutionLog(execution.id, `[${new Date().toISOString()}] ${message}`);
|
||||
};
|
||||
|
||||
try {
|
||||
await log('Starting scanner cache cleanup');
|
||||
|
||||
let result: { volumes: string[]; dirs: string[] };
|
||||
if (cleanupFn) {
|
||||
result = await cleanupFn();
|
||||
} else {
|
||||
const { cleanupScannerCache } = await import('../../scanner');
|
||||
result = await cleanupScannerCache();
|
||||
}
|
||||
|
||||
if (result.volumes.length > 0) {
|
||||
await log(`Removed volumes: ${result.volumes.join(', ')}`);
|
||||
}
|
||||
if (result.dirs.length > 0) {
|
||||
await log(`Removed directories: ${result.dirs.join(', ')}`);
|
||||
}
|
||||
await log(`Cleanup complete: ${result.volumes.length} volumes, ${result.dirs.length} directories removed`);
|
||||
await updateScheduleExecution(execution.id, {
|
||||
status: 'success',
|
||||
completedAt: new Date().toISOString(),
|
||||
duration: Date.now() - startTime,
|
||||
details: { removedVolumes: result.volumes, removedDirs: result.dirs }
|
||||
});
|
||||
} catch (error: any) {
|
||||
await log(`Error: ${error.message}`);
|
||||
await updateScheduleExecution(execution.id, {
|
||||
status: 'failed',
|
||||
completedAt: new Date().toISOString(),
|
||||
duration: Date.now() - startTime,
|
||||
errorMessage: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user