Implemented TASK_CLEANUP_UNUSED_DAYS environment variable. Implemented custom unused cleanup timing. Updated README.md

This commit is contained in:
Glenn de Haan
2026-02-13 18:50:42 +01:00
parent b29150c15b
commit 232caf8a4e
3 changed files with 9 additions and 4 deletions

View File

@@ -172,8 +172,10 @@ services:
TRANSLATION_DEBUG: 'false'
# Enables/disables an automated task to clean up expired vouchers from UniFi
TASK_CLEANUP_EXPIRED: 'false'
# Enables/disables an automated task to clean up unused vouchers (Vouchers unused a day after creation) from UniFi
# Enables/disables an automated task to clean up unused vouchers from UniFi
TASK_CLEANUP_UNUSED: 'false'
# Specifies the amount of days to wait before removing the unused vouchers
TASK_CLEANUP_UNUSED_DAYS: '1'
# Optional volume mapping to override assets
volumes:
- ./branding:/kiosk
@@ -237,7 +239,8 @@ The structure of the file should use lowercase versions of the environment varia
"translation_hidden_languages": "",
"translation_debug": false,
"task_cleanup_expired": false,
"task_cleanup_unused": false
"task_cleanup_unused": false,
"task_cleanup_unused_days": 1
}
```

View File

@@ -55,6 +55,7 @@ module.exports = {
translationDebug: config('translation_debug') || (process.env.TRANSLATION_DEBUG === 'true') || false,
taskCleanupExpired: config('task_cleanup_expired') || (process.env.TASK_CLEANUP_EXPIRED === 'true') || false,
taskCleanupUnused: config('task_cleanup_unused') || (process.env.TASK_CLEANUP_UNUSED === 'true') || false,
taskCleanupUnusedDays: config('task_cleanup_unused_days') || process.env.TASK_CLEANUP_UNUSED_DAYS || 1,
gitTag: process.env.GIT_TAG || 'master',
gitBuild: fs.existsSync('/etc/unifi_voucher_site_build') ? fs.readFileSync('/etc/unifi_voucher_site_build', 'utf-8') : 'Development'
};

View File

@@ -4,6 +4,7 @@
const cache = require('../modules/cache');
const log = require('../modules/log');
const unifi = require('../modules/unifi');
const variables = require('../modules/variables');
/**
* Import own utils
@@ -39,7 +40,7 @@ module.exports = {
},
/**
* Function to clean up unused voucher that are still active after a day
* Function to clean up unused voucher that are still active after defined day(s)
*
* @returns {Promise<unknown>}
*/
@@ -48,7 +49,7 @@ module.exports = {
const vouchers = cache.vouchers.filter((voucher) => {
const today = new Date();
const voucherDate = new Date(voucher.createdAt);
voucherDate.setDate(voucherDate.getDate() + 1);
voucherDate.setDate(voucherDate.getDate() + parseInt(variables.taskCleanupUnusedDays));
return voucherDate.getTime() < today.getTime();
});