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-30 02:36:40 +03:00
|
|
|
await db.queue.load()
|
2022-01-15 18:21:51 +03:00
|
|
|
await db.programs.load()
|
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-31 00:02:13 +03:00
|
|
|
const queue = await db.queue.find({ _id: result._qid }).limit(1)
|
|
|
|
|
if (!queue.length) continue
|
|
|
|
|
const item = queue[0]
|
2022-01-12 13:27:27 +03:00
|
|
|
const programs = result.programs.map(program => {
|
2022-01-19 02:41:56 +03:00
|
|
|
return {
|
|
|
|
|
title: program.title,
|
|
|
|
|
description: program.description || null,
|
2022-01-21 00:01:07 +03:00
|
|
|
category: program.category || null,
|
2022-01-19 02:41:56 +03:00
|
|
|
season: program.season || null,
|
|
|
|
|
episode: program.episode || null,
|
|
|
|
|
icon: program.icon || null,
|
2022-01-31 01:13:23 +03:00
|
|
|
channel: program.channel,
|
2022-01-19 02:41:56 +03:00
|
|
|
lang: program.lang,
|
|
|
|
|
start: program.start,
|
|
|
|
|
stop: program.stop,
|
2022-01-31 00:02:13 +03:00
|
|
|
stop: program.stop,
|
2022-01-31 03:01:05 +03:00
|
|
|
site: item.channel.site,
|
2022-01-30 23:46:20 +03:00
|
|
|
_qid: result._qid
|
2022-01-19 02:41:56 +03:00
|
|
|
}
|
2022-01-09 18:15:38 +03:00
|
|
|
})
|
2022-01-15 16:59:03 +03:00
|
|
|
await db.programs.insert(programs)
|
2022-01-21 19:42:27 +03:00
|
|
|
|
2022-01-30 23:46:20 +03:00
|
|
|
await db.queue.update({ _id: result._qid }, { $set: { error: result.error } })
|
2022-01-15 16:59:03 +03:00
|
|
|
}
|
2022-01-09 18:15:38 +03:00
|
|
|
}
|
2022-01-16 15:31:06 +03:00
|
|
|
|
2022-01-30 02:36:40 +03:00
|
|
|
await db.queue.compact()
|
2022-01-09 18:15:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main()
|