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,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')
},
{}
)