Format cron log

This commit is contained in:
Douglas Barone 2020-11-11 08:40:34 -04:00
parent 970be4c29c
commit 1c2d4cedee

View File

@ -5,18 +5,16 @@ import { format } from 'date-fns'
console.log('Scheduling Tasks...') console.log('Scheduling Tasks...')
function logMsg(msg) {
console.log(`[${format(new Date(), 'HH:MM')}] cron: ${msg}`)
}
cron.schedule( cron.schedule(
'*/5 * * * *', '*/5 * * * *',
async () => { async () => {
console.log( logMsg('updateDBWithOnlineDevices started.')
'[cron exec] updateDBWithOnlineDevices started at ' +
format(new Date(), "d 'de' MMMM 'de' yyyy HH:MM")
)
await updateDBWithOnlineDevices() await updateDBWithOnlineDevices()
console.log( logMsg('updateDBWithOnlineDevices finished.')
'[cron exec] updateDBWithOnlineDevices finished at ' +
format(new Date(), "d 'de' MMMM 'de' yyyy HH:MM")
)
}, },
{} {}
) )
@ -24,13 +22,9 @@ cron.schedule(
cron.schedule( cron.schedule(
'0 0 0 * * *', '0 0 0 * * *',
async () => { async () => {
console.log( logMsg('User.importAllUsers started')
'cron exec: User.importAllUsers started at ' + new Date().toTimeString()
)
await User.importAllUsers() await User.importAllUsers()
console.log( logMsg('User.importAllUsers finished')
'cron exec: User.importAllUsers finished at ' + new Date().toTimeString()
)
}, },
{} {}
) )