Skip to content

Commit

Permalink
feat/increase upload interval (#1606)
Browse files Browse the repository at this point in the history
Download link is expiring to early do to the cleanup not handling
subscriptions table.
  • Loading branch information
aalemayhu authored Sep 29, 2024
1 parent d5fb05b commit 2cd9d00
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
14 changes: 11 additions & 3 deletions src/lib/storage/jobs/ScheduleCleanup.ts
Original file line number Diff line number Diff line change
@@ -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
);
};
2 changes: 2 additions & 0 deletions src/lib/storage/jobs/helpers/deleteOldUploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ 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'),
process.env.UPLOAD_BASE ?? path.join(os.tmpdir(), 'uploads'),
];

deleteOldFiles(locations);
await deleteOldUploads(database);
database.raw(
"DELETE FROM jobs WHERE created_at < NOW() - INTERVAL '14 days' AND status = 'failed'"
);
console.timeEnd('running cleanup');
};

if (require.main === module) {
runCleanup(getDatabase()).then(() => console.log('Cleanup complete'));
runFileSystemCleanup(getDatabase());
console.log('Cleanup complete');
}
2 changes: 1 addition & 1 deletion src/services/EmailService/templates/convert-link.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="container">
<h1 class="title">Your converted deck is ready!</h1>
<p class="subtitle">
Download your converted deck here.
Download your converted deck here. This link is valid for 24 hours.

<a href="{{link}}">{{link}}</a>

Expand Down

0 comments on commit 2cd9d00

Please sign in to comment.