Init commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
|
||||
import { SCHEDULER_INTERVALS_MS } from '@server/initializers/constants.js'
|
||||
import { uploadx } from '../uploadx.js'
|
||||
import { AbstractScheduler } from './abstract-scheduler.js'
|
||||
|
||||
const lTags = loggerTagsFactory('schedulers', 'resumable-upload', 'cleaner')
|
||||
|
||||
export class RemoveDanglingResumableUploadsScheduler extends AbstractScheduler {
|
||||
private static instance: AbstractScheduler
|
||||
private lastExecutionTimeMs: number
|
||||
|
||||
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.REMOVE_DANGLING_RESUMABLE_UPLOADS
|
||||
|
||||
private constructor () {
|
||||
super({ randomRunOnEnable: false })
|
||||
|
||||
this.lastExecutionTimeMs = new Date().getTime()
|
||||
}
|
||||
|
||||
protected async internalExecute () {
|
||||
logger.info('Removing dangling resumable uploads', lTags())
|
||||
|
||||
const now = new Date().getTime()
|
||||
|
||||
try {
|
||||
// Remove files that were not updated since the last execution
|
||||
await uploadx.storage.purge(now - this.lastExecutionTimeMs)
|
||||
} catch (error) {
|
||||
logger.error('Failed to handle file during resumable video upload folder cleanup', { error, ...lTags() })
|
||||
} finally {
|
||||
this.lastExecutionTimeMs = now
|
||||
}
|
||||
}
|
||||
|
||||
static get Instance () {
|
||||
return this.instance || (this.instance = new this())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user