Added performance hooks
This commit is contained in:
parent
f808ec7370
commit
aa75b2ec21
|
@ -8,6 +8,7 @@ import { subMinutes } from 'date-fns'
|
|||
import { logError, logSuccess } from './logger'
|
||||
import { AES, enc } from 'crypto-js'
|
||||
import ip from 'ip'
|
||||
import { performance } from 'perf_hooks'
|
||||
|
||||
import prisma from '../prisma'
|
||||
|
||||
|
@ -59,7 +60,6 @@ function createCommand(devices) {
|
|||
const isWorking = []
|
||||
|
||||
async function updateUserIdMappings() {
|
||||
// console.log('updateUserIdMappings', isWorking)
|
||||
const allDevices = await getDevicesWithUser()
|
||||
|
||||
const pAHosts = await prisma.pAHost.findMany()
|
||||
|
@ -67,6 +67,8 @@ async function updateUserIdMappings() {
|
|||
const jobs = pAHosts.map(async pAHost => {
|
||||
if (isWorking.includes(pAHost.id)) return 0
|
||||
|
||||
const startTime = performance.now()
|
||||
|
||||
const net = ip.cidrSubnet(pAHost.cidr)
|
||||
|
||||
const devices = allDevices.filter(
|
||||
|
@ -74,8 +76,6 @@ async function updateUserIdMappings() {
|
|||
)
|
||||
|
||||
try {
|
||||
// console.log(pAHost.id, pAHost.description, devices.length)
|
||||
|
||||
if (devices.length == 0) return 0
|
||||
|
||||
isWorking.push(pAHost.id)
|
||||
|
@ -92,11 +92,13 @@ async function updateUserIdMappings() {
|
|||
httpsAgent
|
||||
})
|
||||
|
||||
const endTime = performance.now()
|
||||
|
||||
logSuccess({
|
||||
tags: ['paloalto', 'user-id'],
|
||||
message: `Foram mapeados ${devices.length} user-ids em ${
|
||||
pAHost.description || pAHost.cidr
|
||||
}`,
|
||||
} em ${((endTime - startTime) / 1000).toFixed(2)}s.`,
|
||||
data: devices
|
||||
})
|
||||
|
||||
|
@ -115,7 +117,6 @@ async function updateUserIdMappings() {
|
|||
} finally {
|
||||
const index = isWorking.indexOf(pAHost.id)
|
||||
if (index > -1) isWorking.splice(index, 1)
|
||||
// console.log('finally', isWorking)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user