mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update cluster/load.js
Process will be terminated if programs not found
This commit is contained in:
parent
ef6d151596
commit
67ef5aa13e
2 changed files with 41 additions and 24 deletions
|
@ -35,8 +35,8 @@ async function main() {
|
||||||
const total = items.length
|
const total = items.length
|
||||||
|
|
||||||
logger.info('Loading...')
|
logger.info('Loading...')
|
||||||
const results = {}
|
|
||||||
let i = 1
|
let i = 1
|
||||||
|
let totalPrograms = 0
|
||||||
let config = require(file.resolve(items[0].configPath))
|
let config = require(file.resolve(items[0].configPath))
|
||||||
config = _.merge(config, {
|
config = _.merge(config, {
|
||||||
debug: options.debug,
|
debug: options.debug,
|
||||||
|
@ -48,30 +48,42 @@ async function main() {
|
||||||
const grabber = new EPGGrabber(config)
|
const grabber = new EPGGrabber(config)
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const channel = new Channel(item.channel)
|
const channel = new Channel(item.channel)
|
||||||
await grabber.grab(channel, item.date, async (data, err) => {
|
|
||||||
logger.info(
|
|
||||||
`[${i}/${total}] ${channel.site} (${channel.lang}) - ${channel.id} - ${dayjs
|
|
||||||
.utc(data.date)
|
|
||||||
.format('MMM D, YYYY')} (${data.programs.length} programs)`
|
|
||||||
)
|
|
||||||
|
|
||||||
if (err) logger.error(err.message)
|
await new Promise(resolve => {
|
||||||
|
grabber.grab(channel, item.date, async (data, err) => {
|
||||||
|
logger.info(
|
||||||
|
`[${i}/${total}] ${channel.site} (${channel.lang}) - ${channel.id} - ${dayjs
|
||||||
|
.utc(data.date)
|
||||||
|
.format('MMM D, YYYY')} (${data.programs.length} programs)`
|
||||||
|
)
|
||||||
|
|
||||||
const result = {
|
if (err) logger.error(err.message)
|
||||||
_qid: item._id,
|
|
||||||
programs: data.programs,
|
|
||||||
error: err ? err.message : null
|
|
||||||
}
|
|
||||||
|
|
||||||
await file.append(CLUSTER_PATH, JSON.stringify(result) + '\n')
|
const result = {
|
||||||
|
_qid: item._id,
|
||||||
|
programs: data.programs,
|
||||||
|
error: err ? err.message : null
|
||||||
|
}
|
||||||
|
|
||||||
if (i < total) i++
|
await file.append(CLUSTER_PATH, JSON.stringify(result) + '\n')
|
||||||
|
|
||||||
|
totalPrograms += data.programs.length
|
||||||
|
|
||||||
|
if (i < total) i++
|
||||||
|
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
db.queue.compact()
|
db.queue.compact()
|
||||||
|
|
||||||
logger.info(`Done in ${timer.format('HH[h] mm[m] ss[s]')}`)
|
logger.info(`Done in ${timer.format('HH[h] mm[m] ss[s]')}`)
|
||||||
|
|
||||||
|
if (totalPrograms === 0) {
|
||||||
|
logger.error('\nError: No programs found')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -5,17 +5,22 @@ const path = require('path')
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fs.emptyDirSync('tests/__data__/output')
|
fs.emptyDirSync('tests/__data__/output')
|
||||||
fs.copyFileSync('tests/__data__/input/database/queue.db', 'tests/__data__/output/queue.db')
|
fs.copyFileSync('tests/__data__/input/database/queue.db', 'tests/__data__/output/queue.db')
|
||||||
|
|
||||||
execSync(
|
|
||||||
'DB_DIR=tests/__data__/output LOGS_DIR=tests/__data__/output/logs npm run cluster:load -- --cluster-id=1 --timeout=10000',
|
|
||||||
{ encoding: 'utf8' }
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can load cluster', () => {
|
it('can load cluster and will terminate process if programs not found', () => {
|
||||||
expect(content('tests/__data__/output/logs/cluster/load/cluster_1.log')).toEqual(
|
try {
|
||||||
content('tests/__data__/expected/logs/cluster/load/cluster_1.log')
|
execSync(
|
||||||
)
|
'DB_DIR=tests/__data__/output LOGS_DIR=tests/__data__/output/logs npm run cluster:load -- --cluster-id=1 --timeout=10000',
|
||||||
|
{ encoding: 'utf8' }
|
||||||
|
)
|
||||||
|
process.exit(1)
|
||||||
|
} catch (err) {
|
||||||
|
expect(err.status).toBe(1)
|
||||||
|
expect(err.stdout.includes('Error: No programs found')).toBe(true)
|
||||||
|
expect(content('tests/__data__/output/logs/cluster/load/cluster_1.log')).toEqual(
|
||||||
|
content('tests/__data__/expected/logs/cluster/load/cluster_1.log')
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function content(filepath) {
|
function content(filepath) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue