From 6a7aa5acb809f504025d8e5334662a00bed65568 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sat, 9 Feb 2019 10:56:36 -0700 Subject: [PATCH] Reset daily stats @ midnight, duh --- core/config.js | 4 ++++ core/misc_scheduled_events.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 core/misc_scheduled_events.js diff --git a/core/config.js b/core/config.js index bd152e99..73179ced 100644 --- a/core/config.js +++ b/core/config.js @@ -953,6 +953,10 @@ function getDefaultConfig() { eventScheduler : { events : { + resetDailyStats : { + schedule : 'at 12:00:01am', // note: Later.js places this right @ midnight + action : '@method:core/misc_scheduled_events.js:resetDailyStatsScheduledEvent', + }, trimMessageAreas : { // may optionally use [or ]@watch:/path/to/file schedule : 'every 24 hours', diff --git a/core/misc_scheduled_events.js b/core/misc_scheduled_events.js new file mode 100644 index 00000000..64a73ea5 --- /dev/null +++ b/core/misc_scheduled_events.js @@ -0,0 +1,18 @@ +/* jslint node: true */ +'use strict'; + +const StatLog = require('./stat_log.js'); +const SysProps = require('./system_property.js'); + +exports.resetDailyStatsScheduledEvent = resetDailyStatsScheduledEvent; + +function resetDailyStatsScheduledEvent(args, cb) { + // + // Various stats need reset daily + // + [ SysProps.LoginsToday, SysProps.MessagesToday ].forEach(prop => { + StatLog.setNonPersistentSystemStat(prop, 0); + }); + + return cb(null); +}