]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | |
3 | import { SCHEDULER_INTERVALS_MS } from '@server/initializers/constants' | |
4 | import { uploadx } from '../uploadx' | |
5 | import { AbstractScheduler } from './abstract-scheduler' | |
6 | ||
7 | const lTags = loggerTagsFactory('scheduler', 'resumable-upload', 'cleaner') | |
8 | ||
9 | export class RemoveDanglingResumableUploadsScheduler extends AbstractScheduler { | |
10 | ||
11 | private static instance: AbstractScheduler | |
12 | private lastExecutionTimeMs: number | |
13 | ||
14 | protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.REMOVE_DANGLING_RESUMABLE_UPLOADS | |
15 | ||
16 | private constructor () { | |
17 | super() | |
18 | ||
19 | this.lastExecutionTimeMs = new Date().getTime() | |
20 | } | |
21 | ||
22 | protected async internalExecute () { | |
23 | logger.debug('Removing dangling resumable uploads', lTags()) | |
24 | ||
25 | const now = new Date().getTime() | |
26 | ||
27 | try { | |
28 | // Remove files that were not updated since the last execution | |
29 | await uploadx.storage.purge(now - this.lastExecutionTimeMs) | |
30 | } catch (error) { | |
31 | logger.error('Failed to handle file during resumable video upload folder cleanup', { error, ...lTags() }) | |
32 | } finally { | |
33 | this.lastExecutionTimeMs = now | |
34 | } | |
35 | } | |
36 | ||
37 | static get Instance () { | |
38 | return this.instance || (this.instance = new this()) | |
39 | } | |
40 | } |