2022-03-24 19:17:48 +00:00
|
|
|
import { updateAccessPoints } from './lib/accessPoints'
|
2020-12-21 12:14:15 +00:00
|
|
|
import { logError, logInfo } from './lib/logger'
|
|
|
|
import { updateUserIdMappings } from './lib/paloalto'
|
|
|
|
import { updateDevicesInfo } from './lib/wifiDevices'
|
|
|
|
|
2020-12-23 12:29:10 +00:00
|
|
|
const SLEEP_IN_MILLISECONDS = process.env.TASK_SLEEP || 10000
|
2020-12-21 12:14:15 +00:00
|
|
|
|
|
|
|
async function updateDevicesTask() {
|
2021-01-19 20:44:53 +00:00
|
|
|
logInfo({
|
|
|
|
tags: ['task', 'wifiDevices', 'user-id'],
|
|
|
|
message: 'Atualização de dispositivos iniciou.'
|
|
|
|
})
|
2020-12-21 12:14:15 +00:00
|
|
|
|
2021-01-19 20:44:53 +00:00
|
|
|
try {
|
2021-11-03 15:37:58 +00:00
|
|
|
await updateDevicesInfo()
|
|
|
|
updateUserIdMappings()
|
2020-12-21 12:14:15 +00:00
|
|
|
} catch (e) {
|
|
|
|
logError({
|
|
|
|
tags: ['task', 'wifiDevices', 'user-id'],
|
2021-11-03 15:37:58 +00:00
|
|
|
message: `Erro executando tarefa: ${e}`,
|
2020-12-21 12:14:15 +00:00
|
|
|
data: e
|
|
|
|
})
|
|
|
|
} finally {
|
2021-01-19 20:44:53 +00:00
|
|
|
setTimeout(updateDevicesTask, SLEEP_IN_MILLISECONDS)
|
2020-12-21 12:14:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-24 19:17:48 +00:00
|
|
|
async function updateAccessPointsTask() {
|
|
|
|
logInfo({
|
|
|
|
tags: ['task', 'accessPoints'],
|
|
|
|
message: 'Atualização de Access Points iniciou.'
|
|
|
|
})
|
|
|
|
|
|
|
|
try {
|
|
|
|
await updateAccessPoints()
|
|
|
|
} catch (e) {
|
|
|
|
logError({
|
|
|
|
tags: ['task', 'accessPoints'],
|
|
|
|
message: `Erro executando tarefa: ${e}`,
|
|
|
|
data: e
|
|
|
|
})
|
|
|
|
} finally {
|
|
|
|
setTimeout(updateAccessPointsTask, SLEEP_IN_MILLISECONDS)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-08 17:53:33 +00:00
|
|
|
function runTasks() {
|
|
|
|
logInfo({
|
|
|
|
tags: ['task'],
|
2021-01-18 20:57:04 +00:00
|
|
|
message: `Rodando tarefas com ${SLEEP_IN_MILLISECONDS}ms de intervalo.`
|
2021-01-08 17:53:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
updateDevicesTask()
|
2022-03-24 19:17:48 +00:00
|
|
|
updateAccessPointsTask()
|
2021-01-08 17:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export { runTasks }
|