This commit is contained in:
Douglas Barone 2022-04-27 10:39:10 -04:00
parent 9d55bd8f78
commit 47d589b0d5
2 changed files with 10 additions and 9 deletions

View File

@ -1,4 +1,4 @@
import {} from 'dotenv/config' import { } from 'dotenv/config'
import './utils/capitalize' import './utils/capitalize'
import './utils/contains' import './utils/contains'
import './utils/cycle' import './utils/cycle'
@ -9,7 +9,7 @@ import 'regenerator-runtime/runtime'
import { logSuccess } from './lib/logger' import { logSuccess } from './lib/logger'
import { server } from './server' import { server } from './server'
import { runTasks } from './tasks' import { startTasks } from './tasks'
import './cronTasks' import './cronTasks'
server.listen().then(async options => { server.listen().then(async options => {
@ -26,5 +26,5 @@ server.listen().then(async options => {
} }
}) })
runTasks() startTasks()
}) })

View File

@ -5,13 +5,14 @@ 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 runTasks() {
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 { try {
await updateAccessPoints()
await updateDevicesInfo() await updateDevicesInfo()
updateUserIdMappings() updateUserIdMappings()
} catch (e) { } catch (e) {
@ -21,7 +22,7 @@ async function updateDevicesTask() {
data: e data: e
}) })
} finally { } finally {
setTimeout(updateDevicesTask, SLEEP_IN_MILLISECONDS) setTimeout(runTasks, SLEEP_IN_MILLISECONDS)
} }
} }
@ -44,14 +45,14 @@ async function updateAccessPointsTask() {
} }
} }
function runTasks() { function startTasks() {
logInfo({ logInfo({
tags: ['task'], tags: ['task'],
message: `Rodando tarefas com ${SLEEP_IN_MILLISECONDS}ms de intervalo.` message: `Rodando tarefas com ${SLEEP_IN_MILLISECONDS}ms de intervalo.`
}) })
updateDevicesTask() runTasks()
updateAccessPointsTask()
} }
export { runTasks } export { startTasks }