-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add video-upload-tmp-folder-cleaner job
- Loading branch information
1 parent
41b789a
commit 1952fa1
Showing
10 changed files
with
93 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
server/lib/job-queue/handlers/video-upload-tmp-folder-cleaner.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { readdir, unlink, stat } from 'fs-extra' | ||
import { Stats } from 'node:fs' | ||
import * as path from 'path' | ||
import { logger } from '@server/helpers/logger' | ||
import { getTmpPath } from '@server/helpers/utils' | ||
import { SCHEDULER_INTERVALS_MS } from '@server/initializers/constants' | ||
|
||
async function processVideoUploadTmpFolderCleaner () { | ||
const tmpPath = await getTmpPath() | ||
let files: string[] | ||
|
||
logger.debug('processVideoUploadTmpFolderCleaner: Reading files from path %s', tmpPath) | ||
|
||
try { | ||
files = await readdir(tmpPath) | ||
} catch (error) { | ||
logger.error('Failed to read resumable video upload tmp folder.', { error }) | ||
return | ||
} | ||
|
||
logger.debug('processVideoUploadTmpFolderCleaner: Found %d files', files.length) | ||
|
||
await Promise.all(files.map(async function (file) { | ||
const filePath = path.join(tmpPath, file) | ||
let statResult: Stats | ||
|
||
try { | ||
statResult = await stat(filePath) | ||
} catch (error) { | ||
logger.error(`Failed to run stat for ${filePath}`, { error }) | ||
return | ||
} | ||
|
||
// current time (in miliseconds): | ||
const now = new Date().getTime() | ||
// time of last status change, plus 1h (in miliseconds): | ||
const endTime = new Date(statResult.ctime).getTime() + SCHEDULER_INTERVALS_MS.removeTmpVideo | ||
|
||
if (now > endTime) { | ||
try { | ||
await unlink(filePath) | ||
} catch (error) { | ||
logger.error(`Failed to unlink ${filePath}`, { error }) | ||
} | ||
} | ||
})) | ||
} | ||
|
||
// --------------------------------------------------------------------------- | ||
|
||
export { | ||
processVideoUploadTmpFolderCleaner | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters