Use funtion to run tasks

This commit is contained in:
Douglas Barone 2021-01-08 13:53:33 -04:00
parent 9abba52d7d
commit e2542091f8
3 changed files with 13 additions and 9 deletions

View File

@ -6,8 +6,6 @@ import oui from 'oui'
import { deleteOldLogs, log, logInfo, logSuccess } from './lib/logger'
import { updateUserIdMappings } from './lib/paloalto'
logInfo({
tags: ['cron'],
message: 'Scheduling tasks...'

View File

@ -15,7 +15,7 @@ logInfo({
: 'Running in development'
})
import './tasks'
import { runTasks } from './tasks'
import './cronTasks'
server.listen().then(options => {
@ -28,3 +28,5 @@ server.listen().then(options => {
}
})
})
runTasks()

View File

@ -4,11 +4,6 @@ import { updateDevicesInfo } from './lib/wifiDevices'
const SLEEP_IN_MILLISECONDS = process.env.TASK_SLEEP || 10000
logInfo({
tags: ['task'],
message: `Running tasks with ${SLEEP_IN_MILLISECONDS}ms sleeps.`
})
async function updateDevicesTask() {
try {
logInfo({
@ -34,4 +29,13 @@ async function updateDevicesTask() {
}
}
updateDevicesTask()
function runTasks() {
logInfo({
tags: ['task'],
message: `Running tasks with ${SLEEP_IN_MILLISECONDS}ms sleeps.`
})
updateDevicesTask()
}
export { runTasks }