From b52f9253c2a905642a01e510bc91dadeb0db419a Mon Sep 17 00:00:00 2001 From: Hellyson Rodrigo Parteka Date: Fri, 3 Dec 2021 03:26:36 -0300 Subject: [PATCH] add some debug logs --- src/services/file-cache.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/services/file-cache.ts b/src/services/file-cache.ts index 826c26d..1df8d71 100644 --- a/src/services/file-cache.ts +++ b/src/services/file-cache.ts @@ -6,6 +6,7 @@ import {FileCache} from '../models/index.js'; import {TYPES} from '../types.js'; import Config from './config.js'; import PQueue from 'p-queue'; +import debug from '../utils/debug.js'; @injectable() export default class FileCacheProvider { @@ -65,7 +66,7 @@ export default class FileCacheProvider { await FileCache.create({hash, bytes: stats.size, accessedAt: new Date()}); } catch (e: unknown) { - console.error(e); + debug(`Caught error trying to move a finished cache file: ${String(e)}`); } } @@ -87,11 +88,13 @@ export default class FileCacheProvider { private evictOldestIfNecessary() { if (FileCacheProvider.evictionQueue.size === 0 && FileCacheProvider.evictionQueue.pending === 0) { + debug('Adding evictOldest task to queue'); void FileCacheProvider.evictionQueue.add(this.evictOldest.bind(this)); } } private async evictOldest() { + debug('Evicting oldest (if found)'); const [{dataValues: {totalSizeBytes}}] = await FileCache.findAll({ attributes: [ [sequelize.fn('sum', sequelize.col('bytes')), 'totalSizeBytes'], @@ -111,8 +114,11 @@ export default class FileCacheProvider { } // Continue to evict until we're under the limit + debug('Scheduling another eviction'); void FileCacheProvider.evictionQueue.add(this.evictOldest.bind(this)); } + + debug('Finished evictOldest'); } private async removeOrphans() {