feat: add GC for failed PDF417 scans
This commit is contained in:
parent
a573419dd3
commit
63f51f4f3e
1 changed files with 28 additions and 0 deletions
|
|
@ -143,14 +143,41 @@ const readdirRec = rootPath =>
|
||||||
))
|
))
|
||||||
.then(_.flatten)
|
.then(_.flatten)
|
||||||
|
|
||||||
|
// @see lib/customers.js:updateIdCardData()
|
||||||
|
const cleanOldFailedPDF417Scans = () => {
|
||||||
|
let old = new Date()
|
||||||
|
old.setDate(old.getDate() - 2) // 2 days ago
|
||||||
|
old = old.getTime()
|
||||||
|
|
||||||
|
/* NOTE: Small caveat to mtime: last time the file was written to. */
|
||||||
|
const isOld = filestat => filestat.mtimeMs < old
|
||||||
|
|
||||||
|
readdirRec(path.join(OPERATOR_DATA_DIR, 'id-operator'))
|
||||||
|
.then(entries => Promise.all(
|
||||||
|
entries
|
||||||
|
.filter(entry => entry.isFile())
|
||||||
|
.map(entry => fs.stat(entry.path).then(_.set('path', entry.path)))
|
||||||
|
))
|
||||||
|
.then(filestats => Promise.all(
|
||||||
|
filestats
|
||||||
|
.filter(isOld)
|
||||||
|
.map(_.flow(_.get(['path']), fs.unlink))
|
||||||
|
))
|
||||||
|
.catch(err => {
|
||||||
|
console.log("Error cleaning up failed PDF417 scans:", err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// @see lib/machine-loader.js:updateFailedQRScans()
|
// @see lib/machine-loader.js:updateFailedQRScans()
|
||||||
const cleanOldFailedQRScans = () => {
|
const cleanOldFailedQRScans = () => {
|
||||||
const old = new Date()
|
const old = new Date()
|
||||||
old.setDate(old.getDate() - 2) // 2 days ago
|
old.setDate(old.getDate() - 2) // 2 days ago
|
||||||
|
|
||||||
const isOld = filepath => {
|
const isOld = filepath => {
|
||||||
const then = new Date(path.basename(filepath).replace(/-[0-9]+\.jpg$/, ''))
|
const then = new Date(path.basename(filepath).replace(/-[0-9]+\.jpg$/, ''))
|
||||||
return then < old
|
return then < old
|
||||||
}
|
}
|
||||||
|
|
||||||
readdirRec(path.join(OPERATOR_DATA_DIR, 'failedQRScans'))
|
readdirRec(path.join(OPERATOR_DATA_DIR, 'failedQRScans'))
|
||||||
.then(entries => Promise.all(
|
.then(entries => Promise.all(
|
||||||
entries
|
entries
|
||||||
|
|
@ -244,6 +271,7 @@ function doPolling (schema) {
|
||||||
addToQueue(updateCoinAtmRadar, RADAR_UPDATE_INTERVAL, schema, QUEUE.SLOW)
|
addToQueue(updateCoinAtmRadar, RADAR_UPDATE_INTERVAL, schema, QUEUE.SLOW)
|
||||||
addToQueue(pi().pruneMachinesHeartbeat, PRUNE_MACHINES_HEARTBEAT, schema, QUEUE.SLOW, settings)
|
addToQueue(pi().pruneMachinesHeartbeat, PRUNE_MACHINES_HEARTBEAT, schema, QUEUE.SLOW, settings)
|
||||||
addToQueue(cleanOldFailedQRScans, FAILED_SCANS_INTERVAL, schema, QUEUE.SLOW, settings)
|
addToQueue(cleanOldFailedQRScans, FAILED_SCANS_INTERVAL, schema, QUEUE.SLOW, settings)
|
||||||
|
addToQueue(cleanOldFailedPDF417Scans, FAILED_SCANS_INTERVAL, schema, QUEUE.SLOW, settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup (schemasToAdd = [], schemasToRemove = []) {
|
function setup (schemasToAdd = [], schemasToRemove = []) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue