feat: console logs of temp uploads check ups

This commit is contained in:
Bobby 2022-05-07 02:01:33 +07:00
parent 5d3ef6e566
commit 4ecec788d0
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09
3 changed files with 23 additions and 9 deletions

View File

@ -669,8 +669,11 @@ self.bulkDeleteExpired = async (dryrun, verbose) => {
const field = fields[0] const field = fields[0]
const values = result.expired.slice().map(row => row[field]) const values = result.expired.slice().map(row => row[field])
result.failed = await self.bulkDeleteFromDb(field, values, sudo) result.failed = await self.bulkDeleteFromDb(field, values, sudo)
if (verbose && result.failed.length) {
result.failed = result.failed
.map(failed => result.expired.find(file => file[fields[0]] === failed))
}
} }
return result return result
} }

View File

@ -382,15 +382,22 @@ safe.use('/api', api)
temporaryUploadsInProgress = true temporaryUploadsInProgress = true
try { try {
const result = await utils.bulkDeleteExpired() const result = await utils.bulkDeleteExpired(false, isDevMode)
if (result.expired.length) { if (result.expired.length || result.failed.length) {
let logMessage = `Expired uploads: ${result.expired.length} deleted` if (isDevMode) {
if (result.failed.length) { let logMessage = `Expired uploads (${result.expired.length}): ${result.expired.map(file => file.name).join(', ')}`
logMessage += `, ${result.failed.length} errored` if (result.failed.length) {
logMessage += `\nErrored (${result.failed.length}): ${result.failed.map(file => file.name).join(', ')}`
}
logger.debug(logMessage)
} else {
let logMessage = `Expired uploads: ${result.expired.length} deleted`
if (result.failed.length) {
logMessage += `, ${result.failed.length} errored`
}
logger.log(logMessage)
} }
logger.log(logMessage)
} }
} catch (error) { } catch (error) {
// Simply print-out errors, then continue // Simply print-out errors, then continue

View File

@ -31,9 +31,13 @@ const utils = require('../controllers/utilsController')
console.log(expired) console.log(expired)
} }
} }
console.log(`Expired files: ${result.expired.length}`) console.log(`Expired files: ${result.expired.length}`)
if (result.failed) { if (result.failed) {
console.log('WARNING: Some expired files failed to delete!')
for (const failed of result.failed) {
console.log(failed)
}
console.log(`Failed to delete: ${result.failed.length}`) console.log(`Failed to delete: ${result.failed.length}`)
} }
})() })()