Clear working state every hour
This commit is contained in:
parent
e08ea5ab97
commit
828ce3b524
|
@ -12,7 +12,8 @@ import { performance } from 'perf_hooks'
|
||||||
|
|
||||||
import prisma from '../prisma'
|
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 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({
|
const httpsAgent = new https.Agent({
|
||||||
|
@ -21,7 +22,7 @@ const httpsAgent = new https.Agent({
|
||||||
|
|
||||||
async function getDevicesWithUser() {
|
async function getDevicesWithUser() {
|
||||||
const now = new Date()
|
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({
|
const wifiDevices = await prisma.wifiDevice.findMany({
|
||||||
where: {
|
where: {
|
||||||
|
@ -41,7 +42,7 @@ function createCommand(devices) {
|
||||||
const entries = devices.reduce(
|
const entries = devices.reduce(
|
||||||
(entries, device) =>
|
(entries, device) =>
|
||||||
entries +
|
entries +
|
||||||
`<entry name="ifms\\${device.user.sAMAccountName}" ip="${device.ip}" timeout="${TIMEOUT_IN_MINUTES}"/>\n`,
|
`<entry name="ifms\\${device.user.sAMAccountName}" ip="${device.ip}" timeout="${MAP_TIMEOUT_IN_MINUTES}"/>\n`,
|
||||||
''
|
''
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -59,13 +60,20 @@ function createCommand(devices) {
|
||||||
|
|
||||||
const isWorking = []
|
const isWorking = []
|
||||||
|
|
||||||
|
function clearWorkingState() {
|
||||||
|
isWorking.length = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(clearWorkingState, 3600000)
|
||||||
|
|
||||||
async function updateUserIdMappings() {
|
async function updateUserIdMappings() {
|
||||||
const allDevices = await getDevicesWithUser()
|
const allDevices = await getDevicesWithUser()
|
||||||
|
|
||||||
const pAHosts = await prisma.pAHost.findMany()
|
const pAHosts = await prisma.pAHost.findMany()
|
||||||
|
|
||||||
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 `Última execução para ${pAHost.description} ainda em andamento`
|
||||||
|
|
||||||
const startTime = performance.now()
|
const startTime = performance.now()
|
||||||
|
|
||||||
|
@ -76,7 +84,8 @@ async function updateUserIdMappings() {
|
||||||
)
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (devices.length == 0) return 0
|
if (devices.length == 0)
|
||||||
|
return `Nenhum dispositivo encontrado para ${pAHost.description}`
|
||||||
|
|
||||||
isWorking.push(pAHost.id)
|
isWorking.push(pAHost.id)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user