From 615cc76904b855e332a670798c3b1396ea0f1cc5 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:05:34 -0500 Subject: [PATCH] Add storage interval --- src/intervals/storage.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/intervals/storage.ts diff --git a/src/intervals/storage.ts b/src/intervals/storage.ts new file mode 100644 index 0000000..68bc6c8 --- /dev/null +++ b/src/intervals/storage.ts @@ -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); +}