Add storage interval

merge-requests/1/merge
Matthew 2019-11-09 23:05:34 -05:00
parent 2febbdbba4
commit 615cc76904
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 19 additions and 0 deletions

19
src/intervals/storage.ts Normal file
View File

@ -0,0 +1,19 @@
/* eslint-disable no-await-in-loop */
import fs from 'fs-extra';
import { Client } from '..';
export default function storage(client: Client) {
setInterval(async () => {
const accounts = await client.db.Account.find();
for (const account of accounts) {
let bytes = Number(await client.util.exec(`du -bs /home/${account.username}`));
try {
await fs.access(`/var/mail/${account.username}`, fs.constants.F_OK);
bytes += Number(await client.util.exec(`du -bs /var/mail/${account.username}`));
} catch {
bytes += 0;
}
await client.redis.set(`storage-${account.username}`, bytes);
}
}, 300000);
}