2020-11-06 13:31:28 +00:00
|
|
|
import cron from 'node-cron'
|
2020-12-14 20:42:38 +00:00
|
|
|
import { updateDevicesInfo } from './lib/wifiDevices'
|
2020-11-06 13:31:28 +00:00
|
|
|
import { User } from './classes/User'
|
2020-11-10 02:22:36 +00:00
|
|
|
import { format } from 'date-fns'
|
2020-11-30 18:53:43 +00:00
|
|
|
import oui from 'oui'
|
2020-11-06 13:31:28 +00:00
|
|
|
|
2020-12-14 20:18:28 +00:00
|
|
|
import { updateUserIdMappings } from './lib/paloalto'
|
2020-12-02 19:54:49 +00:00
|
|
|
|
2020-11-11 12:45:04 +00:00
|
|
|
function logMsg(msg) {
|
2020-11-16 15:14:22 +00:00
|
|
|
console.log(`[${format(new Date(), 'HH:mm:ss')}] cron: ${msg}`)
|
2020-11-11 12:45:04 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 19:54:49 +00:00
|
|
|
logMsg('Scheduling tasks...')
|
2020-11-06 13:31:28 +00:00
|
|
|
|
2020-12-02 15:20:27 +00:00
|
|
|
cron.schedule('*/1 * * * *', async () => {
|
2020-12-02 19:54:49 +00:00
|
|
|
logMsg('updateDevicesInfo started.')
|
|
|
|
|
|
|
|
const devices = await updateDevicesInfo()
|
2020-12-09 12:30:17 +00:00
|
|
|
|
2020-12-17 17:04:06 +00:00
|
|
|
logMsg(`updateDevicesInfo updated ${devices} devices.`)
|
2020-12-09 12:30:17 +00:00
|
|
|
|
2020-12-17 17:04:06 +00:00
|
|
|
let mappings = 0
|
2020-11-11 15:36:40 +00:00
|
|
|
|
2020-12-17 17:04:06 +00:00
|
|
|
if (devices > 0) {
|
|
|
|
logMsg('updateUserIdMappings started.')
|
|
|
|
mappings = await updateUserIdMappings()
|
|
|
|
logMsg(`updateUserIdMappings updated ${mappings} user-id mappings.`)
|
|
|
|
}
|
2020-11-11 21:12:37 +00:00
|
|
|
})
|
2020-11-06 13:31:28 +00:00
|
|
|
|
|
|
|
cron.schedule(
|
|
|
|
'0 0 0 * * *',
|
2020-11-11 12:47:03 +00:00
|
|
|
async () => {
|
2020-11-11 12:45:04 +00:00
|
|
|
logMsg('User.importAllUsers started')
|
2020-11-06 13:31:28 +00:00
|
|
|
await User.importAllUsers()
|
2020-11-11 12:45:04 +00:00
|
|
|
logMsg('User.importAllUsers finished')
|
2020-11-06 13:31:28 +00:00
|
|
|
},
|
|
|
|
{}
|
|
|
|
)
|
2020-11-30 18:53:43 +00:00
|
|
|
|
|
|
|
cron.schedule('0 0 0 * * *', async () => {
|
|
|
|
await oui.update()
|
|
|
|
logMsg('Oui updated')
|
|
|
|
})
|