diff --git a/server/src/lib/paloalto.js b/server/src/lib/paloalto.js
index 80c8154..4fbc9a4 100644
--- a/server/src/lib/paloalto.js
+++ b/server/src/lib/paloalto.js
@@ -12,7 +12,8 @@ import { performance } from 'perf_hooks'
import prisma from '../prisma'
-const TIMEOUT_IN_MINUTES = process.env.MAPPING_TIMEOUT || '360' // 6 horas
+const MAP_TIMEOUT_IN_MINUTES = process.env.MAPPING_TIMEOUT || '360' // 6 horas
+
const CIDR_RE = /^([0-9]{1,3}\.){3}[0-9]{1,3}(\/([0-9]|[1-2][0-9]|3[0-2]))?$/
const httpsAgent = new https.Agent({
@@ -21,7 +22,7 @@ const httpsAgent = new https.Agent({
async function getDevicesWithUser() {
const now = new Date()
- const timeoutThreshold = subMinutes(now, TIMEOUT_IN_MINUTES)
+ const timeoutThreshold = subMinutes(now, MAP_TIMEOUT_IN_MINUTES)
const wifiDevices = await prisma.wifiDevice.findMany({
where: {
@@ -41,7 +42,7 @@ function createCommand(devices) {
const entries = devices.reduce(
(entries, device) =>
entries +
- `\n`,
+ `\n`,
''
)
@@ -59,13 +60,20 @@ function createCommand(devices) {
const isWorking = []
+function clearWorkingState() {
+ isWorking.length = 0
+}
+
+setInterval(clearWorkingState, 3600000)
+
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
+ if (isWorking.includes(pAHost.id))
+ return `Última execução para ${pAHost.description} ainda em andamento`
const startTime = performance.now()
@@ -76,7 +84,8 @@ async function updateUserIdMappings() {
)
try {
- if (devices.length == 0) return 0
+ if (devices.length == 0)
+ return `Nenhum dispositivo encontrado para ${pAHost.description}`
isWorking.push(pAHost.id)