ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

remove-dangling-resumable-uploads-scheduler.ts 1.2 KiB

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