Move updateAccessPoints to crontasks

This commit is contained in:
Douglas Barone 2022-05-17 15:36:20 +00:00
parent c18efd7049
commit 7bb4c07a2d
2 changed files with 7 additions and 21 deletions

View File

@ -4,6 +4,9 @@ import oui from 'oui'
import { User } from './classes/User'
import { deleteOldLogs, logInfo, logSuccess } from './lib/logger'
import { updateAccessPoints } from './lib/accessPoints'
// WARNING! All crontasks are blocking! Do not await inside it
logInfo({
@ -35,3 +38,7 @@ cron.schedule('0 0 2 * * *', () => {
message: `Logs antigos deletados`
})
})
cron.schedule('0 */2 * * * *', () => {
updateAccessPoints().catch(console.log)
})

View File

@ -12,7 +12,6 @@ async function runTasks() {
})
try {
await updateAccessPoints()
await updateDevicesInfo()
updateUserIdMappings()
} catch (e) {
@ -26,25 +25,6 @@ async function runTasks() {
}
}
async function updateAccessPointsTask() {
logInfo({
tags: ['task', 'accessPoints'],
message: 'Atualização de Access Points iniciou.'
})
try {
await updateAccessPoints()
} catch (e) {
logError({
tags: ['task', 'accessPoints'],
message: `Erro executando tarefa: ${e}`,
data: e
})
} finally {
setTimeout(updateAccessPointsTask, SLEEP_IN_MILLISECONDS)
}
}
function startTasks() {
logInfo({
tags: ['task'],
@ -52,7 +32,6 @@ function startTasks() {
})
runTasks()
}
export { startTasks }