58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
import { updateAccessPoints } from './lib/accessPoints'
|
|
import { logError, logInfo } from './lib/logger'
|
|
import { updateUserIdMappings } from './lib/paloalto'
|
|
import { updateDevicesInfo } from './lib/wifiDevices'
|
|
|
|
const SLEEP_IN_MILLISECONDS = process.env.TASK_SLEEP || 10000
|
|
|
|
async function updateDevicesTask() {
|
|
logInfo({
|
|
tags: ['task', 'wifiDevices', 'user-id'],
|
|
message: 'Atualização de dispositivos iniciou.'
|
|
})
|
|
|
|
try {
|
|
await updateDevicesInfo()
|
|
updateUserIdMappings()
|
|
} catch (e) {
|
|
logError({
|
|
tags: ['task', 'wifiDevices', 'user-id'],
|
|
message: `Erro executando tarefa: ${e}`,
|
|
data: e
|
|
})
|
|
} finally {
|
|
setTimeout(updateDevicesTask, SLEEP_IN_MILLISECONDS)
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
function runTasks() {
|
|
logInfo({
|
|
tags: ['task'],
|
|
message: `Rodando tarefas com ${SLEEP_IN_MILLISECONDS}ms de intervalo.`
|
|
})
|
|
|
|
updateDevicesTask()
|
|
updateAccessPointsTask()
|
|
}
|
|
|
|
export { runTasks }
|