ifms-pti/server/src/cronTasks.js

52 lines
1.1 KiB
JavaScript
Raw Normal View History

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'
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-18 14:53:04 +00:00
import { log } from './lib/logger'
2020-12-14 20:18:28 +00:00
import { updateUserIdMappings } from './lib/paloalto'
2020-12-18 14:53:04 +00:00
function cronLog(message) {
log({
level: 'INFO',
tags: ['cron'],
message,
data: { message }
})
2020-11-11 12:45:04 +00:00
}
2020-12-18 14:53:04 +00:00
cronLog('Scheduling tasks...')
2020-11-06 13:31:28 +00:00
2020-12-02 15:20:27 +00:00
cron.schedule('*/1 * * * *', async () => {
2020-12-18 14:53:04 +00:00
cronLog('updateDevicesInfo started.')
const devices = await updateDevicesInfo()
2020-12-09 12:30:17 +00:00
2020-12-18 14:53:04 +00:00
cronLog(`updateDevicesInfo updated ${devices} devices.`)
2020-12-09 12:30:17 +00:00
2020-12-17 17:04:06 +00:00
let mappings = 0
2020-12-17 17:04:06 +00:00
if (devices > 0) {
2020-12-18 14:53:04 +00:00
cronLog('updateUserIdMappings started.')
2020-12-17 17:04:06 +00:00
mappings = await updateUserIdMappings()
2020-12-18 14:53:04 +00:00
cronLog(`updateUserIdMappings updated ${mappings} user-id mappings.`)
2020-12-17 17:04:06 +00:00
}
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-12-18 14:53:04 +00:00
cronLog('User.importAllUsers started')
2020-11-06 13:31:28 +00:00
await User.importAllUsers()
2020-12-18 14:53:04 +00:00
cronLog('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()
2020-12-18 14:53:04 +00:00
cronLog('Oui updated')
2020-11-30 18:53:43 +00:00
})