Make THRESHOLD functionality more aggressive
This commit is contained in:
parent
91ad4a01cc
commit
1948c32277
3 changed files with 36 additions and 38 deletions
8
app.js
8
app.js
|
@ -171,12 +171,8 @@ if (isMaster) {
|
|||
logger.error("Invalid THRESHOLD config.");
|
||||
process.env.THRESHOLD = undefined;
|
||||
}
|
||||
const dirstat = (await promises.readdir(process.env.TEMPDIR)).map(async (file) => {
|
||||
return new Promise((resolve) => {
|
||||
promises.stat(`${process.env.TEMPDIR}/${file}`).then((stats) => {
|
||||
resolve(stats.size);
|
||||
});
|
||||
});
|
||||
const dirstat = (await promises.readdir(process.env.TEMPDIR)).map((file) => {
|
||||
return promises.stat(`${process.env.TEMPDIR}/${file}`).then((stats) => stats.size);
|
||||
});
|
||||
const size = await Promise.all(dirstat);
|
||||
process.env.DIRSIZECACHE = size.reduce((a, b)=>{
|
||||
|
|
|
@ -59,24 +59,25 @@ export default async (client, cluster, worker, ipc, interaction) => {
|
|||
process.env.DIRSIZECACHE += result.file.length;
|
||||
if (process.env.DIRSIZECACHE > process.env.THRESHOLD) {
|
||||
const files = (await promises.readdir(process.env.TEMPDIR)).map((file) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
promises.stat(`${process.env.TEMPDIR}/${file}`).then((fstats)=>{
|
||||
resolve({
|
||||
return promises.stat(`${process.env.TEMPDIR}/${file}`).then((stats) => {
|
||||
return {
|
||||
name: file,
|
||||
size: fstats.size,
|
||||
ctime: fstats.ctime
|
||||
});
|
||||
}).catch(reject);
|
||||
size: stats.size,
|
||||
ctime: stats.ctime
|
||||
};
|
||||
});
|
||||
});
|
||||
Promise.all(files).then((files) => {
|
||||
process.env.DIRSIZECACHE = files.reduce((a, b)=>{
|
||||
return a+b.size;
|
||||
const resolvedFiles = await Promise.all(files);
|
||||
process.env.DIRSIZECACHE = resolvedFiles.reduce((a, b)=>{
|
||||
return a + b.size;
|
||||
}, 0);
|
||||
const oldestFile = files.sort((a, b) => a.ctime - b.ctime)[0].name;
|
||||
promises.rm(`${process.env.TEMPDIR}/${oldestFile}`);
|
||||
logger.log(`Removed oldest image file: ${oldestFile}`);
|
||||
});
|
||||
const oldestFiles = resolvedFiles.sort((a, b) => a.ctime - b.ctime);
|
||||
while (process.env.DIRSIZECACHE > process.env.THRESHOLD) {
|
||||
await promises.rm(`${process.env.TEMPDIR}/${oldestFiles[0].name}`);
|
||||
process.env.DIRSIZECACHE -= oldestFiles[0].size;
|
||||
logger.log(`Removed oldest image file: ${oldestFiles[0].name}`);
|
||||
oldestFiles.shift();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -149,24 +149,25 @@ export default async (client, cluster, worker, ipc, message) => {
|
|||
process.env.DIRSIZECACHE += result.file.length;
|
||||
if (process.env.DIRSIZECACHE > process.env.THRESHOLD) {
|
||||
const files = (await promises.readdir(process.env.TEMPDIR)).map((file) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
promises.stat(`${process.env.TEMPDIR}/${file}`).then((fstats)=>{
|
||||
resolve({
|
||||
return promises.stat(`${process.env.TEMPDIR}/${file}`).then((stats) => {
|
||||
return {
|
||||
name: file,
|
||||
size: fstats.size,
|
||||
ctime: fstats.ctime
|
||||
});
|
||||
}).catch(reject);
|
||||
size: stats.size,
|
||||
ctime: stats.ctime
|
||||
};
|
||||
});
|
||||
});
|
||||
Promise.all(files).then((files) => {
|
||||
process.env.DIRSIZECACHE = files.reduce((a, b)=>{
|
||||
return a+b.size;
|
||||
const resolvedFiles = await Promise.all(files);
|
||||
process.env.DIRSIZECACHE = resolvedFiles.reduce((a, b)=>{
|
||||
return a + b.size;
|
||||
}, 0);
|
||||
const oldestFile = files.sort((a, b) => a.ctime - b.ctime)[0].name;
|
||||
promises.rm(`${process.env.TEMPDIR}/${oldestFile}`);
|
||||
log(`Removed oldest image file: ${oldestFile}`);
|
||||
});
|
||||
const oldestFiles = resolvedFiles.sort((a, b) => a.ctime - b.ctime);
|
||||
while (process.env.DIRSIZECACHE > process.env.THRESHOLD) {
|
||||
await promises.rm(`${process.env.TEMPDIR}/${oldestFiles[0].name}`);
|
||||
process.env.DIRSIZECACHE -= oldestFiles[0].size;
|
||||
log(`Removed oldest image file: ${oldestFiles[0].name}`);
|
||||
oldestFiles.shift();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue