Update save-results.js

This commit is contained in:
Aleksandr Statciuk 2022-01-21 19:42:27 +03:00
parent 642b09051f
commit 15e54da0e2
4 changed files with 41 additions and 17 deletions

View file

@ -4,8 +4,9 @@ const _ = require('lodash')
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs'
async function main() {
const errorsLog = `${LOGS_DIR}/errors.log`
await file.create(errorsLog)
await db.channels.load()
await db.programs.load()
await db.programs.reset()
const files = await file.list(`${LOGS_DIR}/load-cluster/cluster_*.log`)
@ -13,8 +14,6 @@ async function main() {
logger.info(`Parsing "${filepath}"...`)
const results = await parser.parseLogs(filepath)
for (const result of results) {
await db.channels.update({ _id: result._id }, { $set: { logo: result.logo } })
const programs = result.programs.map(program => {
return {
title: program.title,
@ -27,13 +26,24 @@ async function main() {
lang: program.lang,
start: program.start,
stop: program.stop,
site: result.site,
country: result.country,
gid: result.gid
_cid: result.channel._id
}
})
await db.programs.insert(programs)
if (result.channel.logo) {
await db.channels.update(
{ _id: result.channel._id },
{ $set: { logo: result.channel.logo } }
)
}
if (result.error) {
await file.append(
errorsLog,
JSON.stringify({ ...result.channel, date: result.date, error: result.error }) + '\n'
)
}
}
}