From 47d589b0d591e6a3fd2792331c63a4b452b0f8de Mon Sep 17 00:00:00 2001 From: Douglas Barone Date: Wed, 27 Apr 2022 10:39:10 -0400 Subject: [PATCH] Refactor --- server/src/index.js | 6 +++--- server/src/tasks.js | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/server/src/index.js b/server/src/index.js index bee4acd..6565d72 100755 --- a/server/src/index.js +++ b/server/src/index.js @@ -1,4 +1,4 @@ -import {} from 'dotenv/config' +import { } from 'dotenv/config' import './utils/capitalize' import './utils/contains' import './utils/cycle' @@ -9,7 +9,7 @@ import 'regenerator-runtime/runtime' import { logSuccess } from './lib/logger' import { server } from './server' -import { runTasks } from './tasks' +import { startTasks } from './tasks' import './cronTasks' server.listen().then(async options => { @@ -26,5 +26,5 @@ server.listen().then(async options => { } }) - runTasks() + startTasks() }) diff --git a/server/src/tasks.js b/server/src/tasks.js index e54ebb4..cc91177 100644 --- a/server/src/tasks.js +++ b/server/src/tasks.js @@ -5,13 +5,14 @@ import { updateDevicesInfo } from './lib/wifiDevices' const SLEEP_IN_MILLISECONDS = process.env.TASK_SLEEP || 10000 -async function updateDevicesTask() { +async function runTasks() { logInfo({ tags: ['task', 'wifiDevices', 'user-id'], message: 'Atualização de dispositivos iniciou.' }) try { + await updateAccessPoints() await updateDevicesInfo() updateUserIdMappings() } catch (e) { @@ -21,7 +22,7 @@ async function updateDevicesTask() { data: e }) } finally { - setTimeout(updateDevicesTask, SLEEP_IN_MILLISECONDS) + setTimeout(runTasks, SLEEP_IN_MILLISECONDS) } } @@ -44,14 +45,14 @@ async function updateAccessPointsTask() { } } -function runTasks() { +function startTasks() { logInfo({ tags: ['task'], message: `Rodando tarefas com ${SLEEP_IN_MILLISECONDS}ms de intervalo.` }) - updateDevicesTask() - updateAccessPointsTask() + runTasks() + } -export { runTasks } +export { startTasks }