ifms-pti/server/src/cronTasks.js

36 lines
793 B
JavaScript
Raw Normal View History

2020-11-06 13:31:28 +00:00
import cron from 'node-cron'
import { updateDBWithOnlineDevices } from './utils/wifiUtils'
import { User } from './classes/User'
console.log('Scheduling Tasks...')
cron.schedule(
'*/5 * * * *',
async () => {
console.log(
'cron exec: updateDBWithOnlineDevices started at' +
new Date().toTimeString()
)
await updateDBWithOnlineDevices()
console.log(
'cron exec: updateDBWithOnlineDevices finished at' +
new Date().toTimeString()
)
},
{}
)
cron.schedule(
'0 0 0 * * *',
async () => {
console.log(
'cron exec: User.importAllUsers started at ' + new Date().toTimeString()
)
await User.importAllUsers()
console.log(
'cron exec: User.importAllUsers finished at ' + new Date().toTimeString()
)
},
{}
)