ifms-pti/server/src/tasks.js
Douglas Barone 8d8cdd6486 Added pubsub
2022-03-24 15:17:48 -04:00

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 }