Fix working state
This commit is contained in:
parent
c6d5916b4a
commit
956deb4c69
|
@ -59,6 +59,7 @@ function createCommand(devices) {
|
|||
const isWorking = []
|
||||
|
||||
async function updateUserIdMappings() {
|
||||
// console.log('updateUserIdMappings', isWorking)
|
||||
const allDevices = await getDevicesWithUser()
|
||||
|
||||
const pAHosts = await prisma.pAHost.findMany()
|
||||
|
@ -66,15 +67,17 @@ async function updateUserIdMappings() {
|
|||
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))
|
||||
|
||||
try {
|
||||
// console.log(pAHost.id, pAHost.description, devices.length)
|
||||
|
||||
if (devices.length == 0) return 0
|
||||
|
||||
isWorking.push(pAHost.id)
|
||||
|
||||
const cmd = createCommand(devices)
|
||||
|
||||
await axios({
|
||||
|
@ -109,6 +112,7 @@ async function updateUserIdMappings() {
|
|||
} finally {
|
||||
const index = isWorking.indexOf(pAHost.id)
|
||||
if (index > -1) isWorking.splice(index, 1)
|
||||
// console.log('finally', isWorking)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import prisma from '../prisma'
|
|||
import { pubsub, USER_PRESENCE_UPDATED } from '../pubsub'
|
||||
import { logError, logSuccess } from './logger'
|
||||
|
||||
const DEBOUNCE_TIME_MS = 10000
|
||||
const DEBOUNCE_TIME_MS = 3000
|
||||
const RECENT_THRESHOLD_IN_MINUTES = 5
|
||||
|
||||
let working = false
|
||||
|
|
|
@ -5,12 +5,12 @@ import { updateDevicesInfo } from './lib/wifiDevices'
|
|||
const SLEEP_IN_MILLISECONDS = process.env.TASK_SLEEP || 10000
|
||||
|
||||
async function updateDevicesTask() {
|
||||
try {
|
||||
logInfo({
|
||||
tags: ['task', 'wifiDevices', 'user-id'],
|
||||
message: 'Atualização de dispositivos iniciou.'
|
||||
})
|
||||
|
||||
try {
|
||||
const devicesQnt = await updateDevicesInfo()
|
||||
|
||||
if (devicesQnt > 0) {
|
||||
|
@ -23,9 +23,7 @@ async function updateDevicesTask() {
|
|||
data: e
|
||||
})
|
||||
} finally {
|
||||
setTimeout(() => {
|
||||
updateDevicesTask()
|
||||
}, SLEEP_IN_MILLISECONDS)
|
||||
setTimeout(updateDevicesTask, SLEEP_IN_MILLISECONDS)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user