Daily actions fix, typo fix, incremented maxPWCount

This commit is contained in:
MrFry 2020-04-13 09:20:36 +02:00
parent 3aa36520d4
commit f3e6f21ad5
2 changed files with 22 additions and 8 deletions

View file

@ -47,7 +47,7 @@ const usersDbBackupPath = 'data/dbs/backup'
const maxVeteranPwGetCount = 10 const maxVeteranPwGetCount = 10
const addPWPerDay = 1 // every x day a user can give a pw const addPWPerDay = 1 // every x day a user can give a pw
const maxPWCount = 4 // maximum pw give opportunities a user can have at once const maxPWCount = 6 // maximum pw give opportunities a user can have at once
const daysAfterUserGetsPWs = 2 // days after user gets pw-s const daysAfterUserGetsPWs = 2 // days after user gets pw-s
let userDB let userDB
@ -144,7 +144,7 @@ function GetApp () {
created: utils.GetDateString() created: utils.GetDateString()
}) })
logger.Log(`User #${requestingUser.id} creted new user #${insertRes.lastInsertRowid}`, logger.GetColor('cyan')) logger.Log(`User #${requestingUser.id} created new user #${insertRes.lastInsertRowid}`, logger.GetColor('cyan'))
res.json({ res.json({
result: 'success', result: 'success',
@ -590,6 +590,7 @@ function GetApp () {
function IncrementAvaiblePWs () { function IncrementAvaiblePWs () {
// FIXME: check this if this is legit and works // FIXME: check this if this is legit and works
logger.Log('Incrementing avaible PW-s ...')
const users = dbtools.SelectAll(userDB, 'users') const users = dbtools.SelectAll(userDB, 'users')
const today = new Date() const today = new Date()
const getDayDiff = (dateString) => { const getDayDiff = (dateString) => {
@ -619,14 +620,14 @@ function GetApp () {
}) })
} }
function DailyActions () { function DailyAction () {
ExportDailyDataCount() ExportDailyDataCount()
BackupDB() BackupDB()
IncrementAvaiblePWs() IncrementAvaiblePWs()
} }
return { return {
DailyActions: DailyActions, dailyAction: DailyAction,
app: app app: app
} }
} }

View file

@ -17,7 +17,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
console.clear() process.stdout.write('\u001b[2J\u001b[0;0H') // console.clear()
const startHTTPS = true const startHTTPS = true
const isRoot = process.getuid && process.getuid() === 0 const isRoot = process.getuid && process.getuid() === 0
@ -125,7 +125,7 @@ Object.keys(modules).forEach(function (k, i) {
const modApp = mod.getApp() const modApp = mod.getApp()
x.app = modApp.app x.app = modApp.app
x.dailyAction = modApp.DailyAction x.dailyAction = modApp.dailyAction
x.cleanup = modApp.cleanup x.cleanup = modApp.cleanup
x.urls.forEach((url) => { x.urls.forEach((url) => {
@ -169,10 +169,20 @@ function setLogTimer () {
const night = new Date( const night = new Date(
now.getFullYear(), now.getFullYear(),
now.getMonth(), now.getMonth(),
now.getDate() + 1, // the next day, ... now.getDate() + 1,
0, 0, 0 // ...at 00:00:00 hours 0,
0,
0
) )
logger.DebugLog(`Next daily action: ${night}`, 'daily', 1)
const msToMidnight = night.getTime() - now.getTime() const msToMidnight = night.getTime() - now.getTime()
logger.DebugLog(`msToMidnight: ${msToMidnight}`, 'daily', 1)
logger.DebugLog(`Seconds To Midnight: ${msToMidnight / 1000}`, 'daily', 1)
if (msToMidnight < 0) {
logger.Log(`Error setting up Log Timer, msToMidnight is negative! (${msToMidnight})`, logger.GetColor('redbg'))
return
}
setTimeout(function () { setTimeout(function () {
LogTimerAction() LogTimerAction()
@ -181,10 +191,13 @@ function setLogTimer () {
} }
function LogTimerAction () { function LogTimerAction () {
logger.DebugLog(`Running Log Timer Action`, 'daily', 1)
Object.keys(modules).forEach((k, i) => { Object.keys(modules).forEach((k, i) => {
const x = modules[k] const x = modules[k]
logger.DebugLog(`Ckecking ${k}`, 'daily', 1)
if (x.dailyAction) { if (x.dailyAction) {
try { try {
logger.Log(`Running daily action of ${k}`)
x.dailyAction() x.dailyAction()
} catch (e) { } catch (e) {
logger.Log(`Error in ${k} daily action! Details in STDERR`, logger.GetColor('redbg')) logger.Log(`Error in ${k} daily action! Details in STDERR`, logger.GetColor('redbg'))