From dfd66a56c39aecf6992a8ab98b2a70fef94dc1c3 Mon Sep 17 00:00:00 2001 From: badrAZ Date: Tue, 23 Oct 2018 09:20:11 +0200 Subject: [PATCH] feat(xo-server-usage-report): ability to send daily (#3582) Fixes #3544 --- CHANGELOG.md | 1 + packages/xo-server-usage-report/src/index.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1800c3d81..87005ad28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - [Scheduling] Merge selection and interval tabs [#1902](https://github.com/vatesfr/xen-orchestra/issues/1902) (PR [#3519](https://github.com/vatesfr/xen-orchestra/pull/3519)) - [Backup NG/Restore] The backup selector now also shows the job name [#3366](https://github.com/vatesfr/xen-orchestra/issues/3366) (PR [#3564](https://github.com/vatesfr/xen-orchestra/pull/3564)) - Sort buttons by criticality in tables [#3168](https://github.com/vatesfr/xen-orchestra/issues/3168) (PR [#3545](https://github.com/vatesfr/xen-orchestra/pull/3545)) +- [Usage Report] Ability to send a daily report [#3544](https://github.com/vatesfr/xen-orchestra/issues/3544) (PR [#3582](https://github.com/vatesfr/xen-orchestra/pull/3582)) ### Bug fixes diff --git a/packages/xo-server-usage-report/src/index.js b/packages/xo-server-usage-report/src/index.js index 0cb308eb7..61bed7908 100644 --- a/packages/xo-server-usage-report/src/index.js +++ b/packages/xo-server-usage-report/src/index.js @@ -79,7 +79,7 @@ export const configurationSchema = { }, periodicity: { type: 'string', - enum: ['monthly', 'weekly'], + enum: ['monthly', 'weekly', 'daily'], description: 'If you choose weekly you will receive the report every sunday and if you choose monthly you will receive it every first day of the month.', }, @@ -661,6 +661,12 @@ async function dataBuilder ({ xo, storedStatsPath, all }) { // =================================================================== +const CRON_BY_PERIODICITY = { + monthly: '0 6 1 * *', + weekly: '0 6 * * 0', + daily: '0 6 * * *', +} + class UsageReportPlugin { constructor ({ xo, getDataDir }) { this._xo = xo @@ -681,7 +687,7 @@ class UsageReportPlugin { } this._job = createSchedule( - configuration.periodicity === 'monthly' ? '00 06 1 * *' : '00 06 * * 0' + CRON_BY_PERIODICITY[configuration.periodicity] ).createJob(async () => { try { await this._sendReport(true)