ifms-pti/server/src/tasks.js

38 lines
844 B
JavaScript
Raw Normal View History

2020-12-21 12:14:15 +00:00
import { logError, logInfo } from './lib/logger'
import { updateUserIdMappings } from './lib/paloalto'
import { updateDevicesInfo } from './lib/wifiDevices'
2020-12-23 12:29:10 +00:00
const SLEEP_IN_MILLISECONDS = process.env.TASK_SLEEP || 10000
2020-12-21 12:14:15 +00:00
logInfo({
tags: ['task'],
2020-12-23 12:29:10 +00:00
message: `Running tasks with ${SLEEP_IN_MILLISECONDS}ms sleeps.`
2020-12-21 12:14:15 +00:00
})
async function updateDevicesTask() {
try {
logInfo({
tags: ['task', 'wifiDevices'],
message: 'updateDevicesTask started'
})
2021-01-08 17:50:25 +00:00
const devicesQnt = await updateDevicesInfo()
2020-12-21 12:14:15 +00:00
2021-01-08 17:50:25 +00:00
if (devicesQnt > 0) {
await updateUserIdMappings()
2020-12-21 12:14:15 +00:00
}
} catch (e) {
logError({
tags: ['task', 'wifiDevices', 'user-id'],
message: `Error executing task.`,
data: e
})
} finally {
setTimeout(() => {
updateDevicesTask()
}, SLEEP_IN_MILLISECONDS)
}
}
updateDevicesTask()