Update save-results.js

This commit is contained in:
Aleksandr Statciuk 2022-01-30 20:54:09 +03:00
parent d2e43e46fe
commit 1b63609b7d
4 changed files with 11 additions and 29 deletions

View file

@ -4,8 +4,6 @@ const _ = require('lodash')
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs' const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs'
async function main() { async function main() {
const errorsLog = `${LOGS_DIR}/errors.log`
await file.create(errorsLog)
await db.queue.load() await db.queue.load()
await db.programs.load() await db.programs.load()
await db.programs.reset() await db.programs.reset()
@ -34,15 +32,8 @@ async function main() {
await db.queue.update( await db.queue.update(
{ _id: result.channel._id }, { _id: result.channel._id },
{ $set: { programCount: result.programs.length } } { $set: { programCount: result.programs.length, error: result.error } }
) )
if (result.error) {
await file.append(
errorsLog,
JSON.stringify({ ...result.channel, date: result.date, error: result.error }) + '\n'
)
}
} }
} }

View file

@ -0,0 +1,4 @@
{"lang":"en","xmltv_id":"BravoEast.us","site_id":"237","site":"directv.com","configPath":"sites/directv.com/directv.com.config.js","groups":["us/directv.com"],"cluster_id":84,"programCount":0,"error":"Invalid header value char","_id":"00AluKCrCnfgrl8W"}
{"lang":"fr","xmltv_id":"CNNInternationalEurope.us","site_id":"53","site":"chaines-tv.orange.fr","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["fr/chaines-tv.orange.fr","bh/chaines-tv.orange.fr"],"cluster_id":1,"programCount":23,"error":null,"_id":"0Wefq0oMR3feCcuY"}
{"lang":"ru","xmltv_id":"CNNInternationalEurope.us","site_id":"140","site":"magticom.ge","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["ge/magticom.ge"],"cluster_id":1,"programCount":0,"error":null,"_id":"1XzrxNkSF2AQNBrT"}
{"lang":"en","xmltv_id":"MNetMovies2.za","site_id":"404a052b-3dea-4cac-a19c-de9a7d6f191d#MAP","site":"dstv.com","configPath":"sites/dstv.com/dstv.com.config.js","groups":["zw/dstv.com"],"cluster_id":120,"programCount":14,"error":null,"_id":"1lnhXpN7g0ER5XwN"}

View file

@ -1,4 +1,4 @@
{"lang":"en","xmltv_id":"BravoEast.us","site_id":"237","site":"directv.com","configPath":"sites/directv.com/directv.com.config.js","groups":["us/directv.com"],"cluster_id":84,"programCount":0,"_id":"00AluKCrCnfgrl8W"} {"lang":"en","xmltv_id":"BravoEast.us","site_id":"237","site":"directv.com","configPath":"sites/directv.com/directv.com.config.js","groups":["us/directv.com"],"cluster_id":84,"programCount":0,"error":"Invalid header value char","_id":"00AluKCrCnfgrl8W"}
{"lang":"fr","xmltv_id":"CNNInternationalEurope.us","site_id":"53","site":"chaines-tv.orange.fr","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["fr/chaines-tv.orange.fr", "bh/chaines-tv.orange.fr"],"cluster_id":1,"programCount":32,"_id":"0Wefq0oMR3feCcuY"} {"lang":"fr","xmltv_id":"CNNInternationalEurope.us","site_id":"53","site":"chaines-tv.orange.fr","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["fr/chaines-tv.orange.fr", "bh/chaines-tv.orange.fr"],"cluster_id":1,"programCount":32,"error":null,"_id":"0Wefq0oMR3feCcuY"}
{"lang":"ru","xmltv_id":"CNNInternationalEurope.us","site_id":"140","site":"magticom.ge","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["ge/magticom.ge"],"cluster_id":1,"programCount":0,"_id":"1XzrxNkSF2AQNBrT"} {"lang":"ru","xmltv_id":"CNNInternationalEurope.us","site_id":"140","site":"magticom.ge","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["ge/magticom.ge"],"cluster_id":1,"programCount":0,"error":null,"_id":"1XzrxNkSF2AQNBrT"}
{"lang":"en","xmltv_id":"MNetMovies2.za","site_id":"404a052b-3dea-4cac-a19c-de9a7d6f191d#MAP","site":"dstv.com","configPath":"sites/dstv.com/dstv.com.config.js","groups":["zw/dstv.com"],"cluster_id":120,"programCount":14,"_id":"1lnhXpN7g0ER5XwN"} {"lang":"en","xmltv_id":"MNetMovies2.za","site_id":"404a052b-3dea-4cac-a19c-de9a7d6f191d#MAP","site":"dstv.com","configPath":"sites/dstv.com/dstv.com.config.js","groups":["zw/dstv.com"],"cluster_id":120,"programCount":14,"error":null,"_id":"1lnhXpN7g0ER5XwN"}

View file

@ -36,22 +36,9 @@ it('can save programs to database', () => {
it('can update queue', () => { it('can update queue', () => {
const output = content('tests/__data__/output/database/queue.db') const output = content('tests/__data__/output/database/queue.db')
const expected = content('tests/__data__/expected/database/queue-with-errors.db')
expect(output[1]).toMatchObject({ expect(output).toEqual(expected)
_id: '0Wefq0oMR3feCcuY',
programCount: 23
})
})
it('can save errors', () => {
const output = content('tests/__data__/input/logs/errors.log')
expect(output[0]).toMatchObject({
_id: '00AluKCrCnfgrl8W',
site: 'directv.com',
xmltv_id: 'BravoEast.us',
error: 'Invalid header value char'
})
}) })
function content(filepath) { function content(filepath) {