2022-01-09 18:15:38 +03:00
|
|
|
const { db, logger, file, parser } = require('../core')
|
|
|
|
|
const _ = require('lodash')
|
|
|
|
|
|
2022-01-09 20:14:41 +03:00
|
|
|
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs'
|
2022-01-09 18:15:38 +03:00
|
|
|
|
|
|
|
|
async function main() {
|
2022-01-10 15:00:35 +03:00
|
|
|
await db.programs.reset()
|
2022-01-09 20:14:41 +03:00
|
|
|
const files = await file.list(`${LOGS_DIR}/load-cluster/cluster_*.log`)
|
2022-01-09 18:15:38 +03:00
|
|
|
for (const filepath of files) {
|
2022-01-15 16:59:03 +03:00
|
|
|
logger.info(`Parsing "${filepath}"...`)
|
2022-01-09 18:15:38 +03:00
|
|
|
const results = await parser.parseLogs(filepath)
|
2022-01-15 16:59:03 +03:00
|
|
|
for (const result of results) {
|
2022-01-12 13:27:27 +03:00
|
|
|
const programs = result.programs.map(program => {
|
|
|
|
|
program.site = result.site
|
|
|
|
|
program.country = result.country
|
2022-01-14 17:55:51 +03:00
|
|
|
program.gid = result.gid
|
2022-01-12 13:27:27 +03:00
|
|
|
|
|
|
|
|
return program
|
2022-01-09 18:15:38 +03:00
|
|
|
})
|
2022-01-15 16:59:03 +03:00
|
|
|
|
|
|
|
|
await db.programs.insert(programs)
|
|
|
|
|
}
|
2022-01-09 18:15:38 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main()
|