Added performance hooks

This commit is contained in:
Douglas Barone 2021-11-03 11:59:23 -04:00
parent f808ec7370
commit aa75b2ec21

View File

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