40 lines
809 B
JavaScript
40 lines
809 B
JavaScript
import { logError, logInfo } from './lib/logger'
|
|
import { updateUserIdMappings } from './lib/paloalto'
|
|
import { updateDevicesInfo } from './lib/wifiDevices'
|
|
|
|
const SLEEP_IN_MILLISECONDS = 10000
|
|
|
|
logInfo({
|
|
tags: ['task'],
|
|
message: 'Starting tasks...'
|
|
})
|
|
|
|
async function updateDevicesTask() {
|
|
try {
|
|
logInfo({
|
|
tags: ['task', 'wifiDevices'],
|
|
message: 'updateDevicesTask started'
|
|
})
|
|
|
|
const devices = await updateDevicesInfo()
|
|
|
|
let mappings = 0
|
|
|
|
if (devices > 0) {
|
|
mappings = await updateUserIdMappings()
|
|
}
|
|
} catch (e) {
|
|
logError({
|
|
tags: ['task', 'wifiDevices', 'user-id'],
|
|
message: `Error executing task.`,
|
|
data: e
|
|
})
|
|
} finally {
|
|
setTimeout(() => {
|
|
updateDevicesTask()
|
|
}, SLEEP_IN_MILLISECONDS)
|
|
}
|
|
}
|
|
|
|
updateDevicesTask()
|