42 lines
899 B
JavaScript
42 lines
899 B
JavaScript
import { logError, logInfo } from './lib/logger'
|
|
import { updateUserIdMappings } from './lib/paloalto'
|
|
import { updateDevicesInfo } from './lib/wifiDevices'
|
|
|
|
const SLEEP_IN_MILLISECONDS = process.env.TASK_SLEEP || 10000
|
|
|
|
async function updateDevicesTask() {
|
|
try {
|
|
logInfo({
|
|
tags: ['task', 'wifiDevices'],
|
|
message: 'updateDevicesTask started'
|
|
})
|
|
|
|
const devicesQnt = await updateDevicesInfo()
|
|
|
|
if (devicesQnt > 0) {
|
|
await updateUserIdMappings()
|
|
}
|
|
} catch (e) {
|
|
logError({
|
|
tags: ['task', 'wifiDevices', 'user-id'],
|
|
message: `Error executing task.`,
|
|
data: e
|
|
})
|
|
} finally {
|
|
setTimeout(() => {
|
|
updateDevicesTask()
|
|
}, SLEEP_IN_MILLISECONDS)
|
|
}
|
|
}
|
|
|
|
function runTasks() {
|
|
logInfo({
|
|
tags: ['task'],
|
|
message: `Running tasks with ${SLEEP_IN_MILLISECONDS}ms sleeps.`
|
|
})
|
|
|
|
updateDevicesTask()
|
|
}
|
|
|
|
export { runTasks }
|