import "dotenv/config"; import { HashedCacheManager } from "../../caching-service/hashed-cache-manager.js"; import { SQLiteCoordinator } from "../../sqlite-service/index.js"; import { sdkLogger as logger } from "../../../services/reporting-service/logger.js"; import { getEnvString } from "../../../utils/env.js"; import { summarizeError } from "../../../utils/error-utils.js"; import { signalBreeJobComplete } from "../utils/bree-worker-complete.js"; // Configure the logger with the correct log level logger.level = getEnvString("LOG_LEVEL", "info"); const main = async () => { const cacheManager = new HashedCacheManager(); try { logger.info( "==========Starting clean-up-expired-cache job cycle==========" ); await SQLiteCoordinator.executeWithLock("clean-up-cache", async () => { await cacheManager.removeExpiredObjects(); }); logger.info( "==========Completed clean-up-expired-cache job cycle==========" ); } catch (error) { logger.error('Worker for job "clean-up-expired-cache" had an error', { error: summarizeError(error), }); throw error; // Rethrow so Bree can handle it properly } finally { await cacheManager.destroy(); logger.info(`==========Completed clean-up-expired-cache job==========`); } }; // Cross-platform module detection fix for Bree compatibility // Windows: process.argv[1] uses backslashes, import.meta.url uses forward slashes // Linux/Mac: both use forward slashes, so this normalization is safe const normalizedArgv1 = process.argv[1].replace(/\\/g, '/'); const fileUrl = normalizedArgv1.startsWith('/') ? `file://${normalizedArgv1}` : // Unix: file:// + /path = file:///path `file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path const isMainModule = import.meta.url === fileUrl; if (isMainModule) { // This is called when Bree runs this file as a worker try { await main(); signalBreeJobComplete(); } catch { process.exit(1); } } export default main;