ifms-pti/server/src/cronTasks.js

45 lines
840 B
JavaScript
Raw Normal View History

2020-11-06 13:31:28 +00:00
import cron from 'node-cron'
2020-11-30 18:53:43 +00:00
import oui from 'oui'
2020-11-06 13:31:28 +00:00
2021-01-15 10:54:55 +00:00
import { User } from './classes/User'
import { deleteOldLogs, log, logInfo, logSuccess } from './lib/logger'
2020-12-18 14:53:04 +00:00
logInfo({
tags: ['cron'],
message: 'Scheduling tasks...'
})
2020-11-06 13:31:28 +00:00
cron.schedule(
'0 0 0 * * *',
2020-11-11 12:47:03 +00:00
async () => {
logInfo({
tags: ['cron', 'user'],
message: `User.importAllUsers started`
})
2020-12-18 18:33:34 +00:00
const users = await User.importAllUsers()
2020-12-18 18:33:34 +00:00
logInfo({
tags: ['cron', 'user'],
2020-12-18 18:33:34 +00:00
message: `User.importAllUsers imported ${users} users`
})
2020-11-06 13:31:28 +00:00
},
{}
)
2020-11-30 18:53:43 +00:00
cron.schedule('0 0 0 * * *', async () => {
await oui.update()
logSuccess({
tags: ['cron', 'oui'],
message: `OUI list updated`
})
})
cron.schedule('0 0 0 * * *', async () => {
await deleteOldLogs()
logSuccess({
tags: ['cron', 'log'],
message: `Old logs deleted`
})
2020-11-30 18:53:43 +00:00
})