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