Created tasks
This commit is contained in:
parent
67d9a30c00
commit
26429f6968
|
@ -13,35 +13,35 @@ logInfo({
|
|||
message: 'Scheduling tasks...'
|
||||
})
|
||||
|
||||
cron.schedule('*/1 * * * *', async () => {
|
||||
logInfo({
|
||||
tags: ['cron', 'wifiDevices'],
|
||||
message: 'updateDevicesInfo started'
|
||||
})
|
||||
// cron.schedule('*/1 * * * *', async () => {
|
||||
// logInfo({
|
||||
// tags: ['cron', 'wifiDevices'],
|
||||
// message: 'updateDevicesInfo started'
|
||||
// })
|
||||
|
||||
const devices = await updateDevicesInfo()
|
||||
// const devices = await updateDevicesInfo()
|
||||
|
||||
logInfo({
|
||||
tags: ['cron', 'wifiDevices'],
|
||||
message: `updateDevicesInfo updated ${devices} devices`
|
||||
})
|
||||
// logInfo({
|
||||
// tags: ['cron', 'wifiDevices'],
|
||||
// message: `updateDevicesInfo updated ${devices} devices`
|
||||
// })
|
||||
|
||||
let mappings = 0
|
||||
// let mappings = 0
|
||||
|
||||
if (devices > 0) {
|
||||
logInfo({
|
||||
tags: ['cron', 'user-id'],
|
||||
message: `updateUserIdMappings started`
|
||||
})
|
||||
// if (devices > 0) {
|
||||
// logInfo({
|
||||
// tags: ['cron', 'user-id'],
|
||||
// message: `updateUserIdMappings started`
|
||||
// })
|
||||
|
||||
mappings = await updateUserIdMappings()
|
||||
// mappings = await updateUserIdMappings()
|
||||
|
||||
logInfo({
|
||||
tags: ['cron', 'user-id'],
|
||||
message: `updateUserIdMappings updated ${mappings} user-id mappings`
|
||||
})
|
||||
}
|
||||
})
|
||||
// logInfo({
|
||||
// tags: ['cron', 'user-id'],
|
||||
// message: `updateUserIdMappings updated ${mappings} user-id mappings`
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
|
||||
cron.schedule(
|
||||
'0 0 0 * * *',
|
||||
|
|
|
@ -4,8 +4,6 @@ import './utils/capitalize'
|
|||
import { logInfo, logSuccess } from './lib/logger'
|
||||
import { server } from './server'
|
||||
|
||||
import './cronTasks'
|
||||
|
||||
logInfo({
|
||||
tags: ['server'],
|
||||
level: 'SUCCESS',
|
||||
|
@ -15,6 +13,9 @@ logInfo({
|
|||
: 'Running in development'
|
||||
})
|
||||
|
||||
import './tasks'
|
||||
import './cronTasks'
|
||||
|
||||
server.listen().then(options => {
|
||||
logSuccess({
|
||||
tags: ['server'],
|
||||
|
|
39
server/src/tasks.js
Normal file
39
server/src/tasks.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
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()
|
Loading…
Reference in New Issue
Block a user