From 2cd9d00774dd8885cd7e077cdadf26e450c015bb Mon Sep 17 00:00:00 2001 From: Alexander Alemayhu Date: Sun, 29 Sep 2024 20:09:24 +0200 Subject: [PATCH] feat/increase upload interval (#1606) Download link is expiring to early do to the cleanup not handling subscriptions table. --- src/lib/storage/jobs/ScheduleCleanup.ts | 14 +++++++++++--- src/lib/storage/jobs/helpers/deleteOldUploads.ts | 2 ++ .../{runCleanup.ts => runFileSystemCleanup.ts} | 7 +++---- .../EmailService/templates/convert-link.html | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) rename src/lib/storage/jobs/helpers/{runCleanup.ts => runFileSystemCleanup.ts} (73%) diff --git a/src/lib/storage/jobs/ScheduleCleanup.ts b/src/lib/storage/jobs/ScheduleCleanup.ts index 8faf758c1..68737a007 100644 --- a/src/lib/storage/jobs/ScheduleCleanup.ts +++ b/src/lib/storage/jobs/ScheduleCleanup.ts @@ -1,8 +1,16 @@ import { Knex } from 'knex'; -import { MS_21 } from './helpers/deleteOldUploads'; -import { runCleanup } from './helpers/runCleanup'; +import deleteOldUploads, { + MS_21, + MS_24_HOURS, +} from './helpers/deleteOldUploads'; +import { runFileSystemCleanup } from './helpers/runFileSystemCleanup'; export const ScheduleCleanup = (db: Knex) => { - setInterval(() => runCleanup(db), MS_21); + setInterval(() => runFileSystemCleanup(db), MS_21); + + setInterval( + () => deleteOldUploads(db).then(() => console.info('deleted old uploads')), + MS_24_HOURS + ); }; diff --git a/src/lib/storage/jobs/helpers/deleteOldUploads.ts b/src/lib/storage/jobs/helpers/deleteOldUploads.ts index 45e893f0d..128d5a231 100644 --- a/src/lib/storage/jobs/helpers/deleteOldUploads.ts +++ b/src/lib/storage/jobs/helpers/deleteOldUploads.ts @@ -5,6 +5,8 @@ import { TIME_21_MINUTES_AS_SECONDS } from '../../../constants'; import StorageHandler from '../../StorageHandler'; export const MS_21 = TIME_21_MINUTES_AS_SECONDS * 1000; +export const MS_24_HOURS = 1000 * 60 * 60 * 24; + const MAX_KEYS = 100_000; const deleteNonSubScriberUploads = async ( diff --git a/src/lib/storage/jobs/helpers/runCleanup.ts b/src/lib/storage/jobs/helpers/runFileSystemCleanup.ts similarity index 73% rename from src/lib/storage/jobs/helpers/runCleanup.ts rename to src/lib/storage/jobs/helpers/runFileSystemCleanup.ts index a4c7a8838..dc4c8940a 100644 --- a/src/lib/storage/jobs/helpers/runCleanup.ts +++ b/src/lib/storage/jobs/helpers/runFileSystemCleanup.ts @@ -4,10 +4,9 @@ import os from 'os'; import { Knex } from 'knex'; import deleteOldFiles from './deleteOldFiles'; -import deleteOldUploads from './deleteOldUploads'; import { getDatabase } from '../../../../data_layer'; -export const runCleanup = async (database: Knex) => { +export const runFileSystemCleanup = (database: Knex) => { console.time('running cleanup'); const locations = [ process.env.WORKSPACE_BASE ?? path.join(os.tmpdir(), 'workspaces'), @@ -15,7 +14,6 @@ export const runCleanup = async (database: Knex) => { ]; deleteOldFiles(locations); - await deleteOldUploads(database); database.raw( "DELETE FROM jobs WHERE created_at < NOW() - INTERVAL '14 days' AND status = 'failed'" ); @@ -23,5 +21,6 @@ export const runCleanup = async (database: Knex) => { }; if (require.main === module) { - runCleanup(getDatabase()).then(() => console.log('Cleanup complete')); + runFileSystemCleanup(getDatabase()); + console.log('Cleanup complete'); } diff --git a/src/services/EmailService/templates/convert-link.html b/src/services/EmailService/templates/convert-link.html index eb01381d3..455b47935 100644 --- a/src/services/EmailService/templates/convert-link.html +++ b/src/services/EmailService/templates/convert-link.html @@ -13,7 +13,7 @@

Your converted deck is ready!

- Download your converted deck here. + Download your converted deck here. This link is valid for 24 hours. {{link}}