Run user-id updates independently

This commit is contained in:
Douglas Barone 2021-01-19 12:32:39 -04:00
parent 2127956af6
commit d0f2feb4ad
2 changed files with 12 additions and 3 deletions

View File

@ -56,12 +56,18 @@ function createCommand(devices) {
</uid-message>`
}
const isWorking = []
async function updateUserIdMappings() {
const allDevices = await getDevicesWithUser()
const pAHosts = await prisma.pAHost.findMany()
const jobs = pAHosts.map(async pAHost => {
if (isWorking.includes(pAHost.id)) return 0
isWorking.push(pAHost.id)
const net = ip.cidrSubnet(pAHost.cidr)
const devices = allDevices.filter(device => net.contains(device.ip))
@ -82,7 +88,7 @@ async function updateUserIdMappings() {
})
logSuccess({
tags: ['user-id', 'paloalto'],
tags: ['paloalto', 'user-id'],
message: `Foram mapeados ${devices.length} user-ids em ${
pAHost.description || pAHost.cidr
}`,
@ -100,6 +106,9 @@ async function updateUserIdMappings() {
})
return 'Não foi possível atualizar. Veja o log do servidor'
} finally {
const index = isWorking.indexOf(pAHost.id)
if (index > -1) isWorking.splice(index, 1)
}
})

View File

@ -7,14 +7,14 @@ const SLEEP_IN_MILLISECONDS = process.env.TASK_SLEEP || 10000
async function updateDevicesTask() {
try {
logInfo({
tags: ['task', 'wifiDevices'],
tags: ['task', 'wifiDevices', 'user-id'],
message: 'Atualização de dispositivos iniciou.'
})
const devicesQnt = await updateDevicesInfo()
if (devicesQnt > 0) {
await updateUserIdMappings()
updateUserIdMappings()
}
} catch (e) {
logError({