From 1c2d4cedee567e1a87b3680a88d7b981f35b520e Mon Sep 17 00:00:00 2001 From: Douglas Barone Date: Wed, 11 Nov 2020 08:40:34 -0400 Subject: [PATCH] Format cron log --- server/src/cronTasks.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/server/src/cronTasks.js b/server/src/cronTasks.js index 7127668..cc0071d 100644 --- a/server/src/cronTasks.js +++ b/server/src/cronTasks.js @@ -5,32 +5,26 @@ import { format } from 'date-fns' console.log('Scheduling Tasks...') +function logMsg(msg) { + console.log(`[${format(new Date(), 'HH:MM')}] cron: ${msg}`) +} + cron.schedule( '*/5 * * * *', async () => { - console.log( - '[cron exec] updateDBWithOnlineDevices started at ' + - format(new Date(), "d 'de' MMMM 'de' yyyy HH:MM") - ) + logMsg('updateDBWithOnlineDevices started.') await updateDBWithOnlineDevices() - console.log( - '[cron exec] updateDBWithOnlineDevices finished at ' + - format(new Date(), "d 'de' MMMM 'de' yyyy HH:MM") - ) + logMsg('updateDBWithOnlineDevices finished.') }, {} ) cron.schedule( '0 0 0 * * *', - async () => { - console.log( - 'cron exec: User.importAllUsers started at ' + new Date().toTimeString() - ) + async () => { + logMsg('User.importAllUsers started') await User.importAllUsers() - console.log( - 'cron exec: User.importAllUsers finished at ' + new Date().toTimeString() - ) + logMsg('User.importAllUsers finished') }, {} )