mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update load-cluster.js
This commit is contained in:
parent
b15ed0a4c6
commit
0161ac02d0
3 changed files with 23 additions and 30 deletions
|
@ -26,16 +26,16 @@ async function main() {
|
||||||
logger.info(`Loading cluster: ${options.clusterId}`)
|
logger.info(`Loading cluster: ${options.clusterId}`)
|
||||||
logger.info(`Creating '${clusterLog}'...`)
|
logger.info(`Creating '${clusterLog}'...`)
|
||||||
await file.create(clusterLog)
|
await file.create(clusterLog)
|
||||||
await db.channels.load()
|
await db.queue.load()
|
||||||
const channels = await db.channels.find({ cluster_id: options.clusterId })
|
const items = await db.queue.find({ cluster_id: options.clusterId })
|
||||||
const total = options.days * channels.length
|
const total = options.days * items.length
|
||||||
logger.info(`Total ${total} requests`)
|
logger.info(`Total ${total} requests`)
|
||||||
|
|
||||||
logger.info('Loading...')
|
logger.info('Loading...')
|
||||||
const results = {}
|
const results = {}
|
||||||
let i = 1
|
let i = 1
|
||||||
for (const channel of channels) {
|
for (const item of items) {
|
||||||
let config = require(file.resolve(channel.configPath))
|
let config = require(file.resolve(item.configPath))
|
||||||
|
|
||||||
config = _.merge(config, {
|
config = _.merge(config, {
|
||||||
days: options.days,
|
days: options.days,
|
||||||
|
@ -46,11 +46,11 @@ async function main() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
await grabber.grab(channel, config, async (data, err) => {
|
await grabber.grab(item, config, async (data, err) => {
|
||||||
logger.info(
|
logger.info(
|
||||||
`[${i}/${total}] ${channel.site} - ${channel.xmltv_id} - ${data.date.format(
|
`[${i}/${total}] ${item.site} - ${item.xmltv_id} - ${data.date.format('MMM D, YYYY')} (${
|
||||||
'MMM D, YYYY'
|
data.programs.length
|
||||||
)} (${data.programs.length} programs)`
|
} programs)`
|
||||||
)
|
)
|
||||||
|
|
||||||
if (err) logger.error(err.message)
|
if (err) logger.error(err.message)
|
||||||
|
@ -68,7 +68,7 @@ async function main() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
db.channels.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]')}`)
|
||||||
}
|
}
|
||||||
|
|
2
tests/__data__/expected/logs/load-cluster/cluster_1.log
Normal file
2
tests/__data__/expected/logs/load-cluster/cluster_1.log
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
{"channel":{"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"},"programs":[],"date":"2022-01-29T00:00:00Z","error":null}
|
||||||
|
{"channel":{"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"},"programs":[],"date":"2022-01-29T00:00:00Z","error":null}
|
|
@ -11,10 +11,7 @@ beforeEach(() => {
|
||||||
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
||||||
fs.mkdirSync('tests/__data__/output')
|
fs.mkdirSync('tests/__data__/output')
|
||||||
fs.mkdirSync('tests/__data__/temp/database', { recursive: true })
|
fs.mkdirSync('tests/__data__/temp/database', { recursive: true })
|
||||||
fs.copyFileSync(
|
fs.copyFileSync('tests/__data__/input/database/queue.db', 'tests/__data__/temp/database/queue.db')
|
||||||
'tests/__data__/input/database/channels.db',
|
|
||||||
'tests/__data__/temp/database/channels.db'
|
|
||||||
)
|
|
||||||
|
|
||||||
execSync(
|
execSync(
|
||||||
'DB_DIR=tests/__data__/temp/database LOGS_DIR=tests/__data__/output/logs node scripts/commands/load-cluster.js --cluster-id=1 --timeout=10000',
|
'DB_DIR=tests/__data__/temp/database LOGS_DIR=tests/__data__/output/logs node scripts/commands/load-cluster.js --cluster-id=1 --timeout=10000',
|
||||||
|
@ -23,25 +20,19 @@ beforeEach(() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can load cluster', () => {
|
it('can load cluster', () => {
|
||||||
const output = content('tests/__data__/output/logs/load-cluster/cluster_1.log')
|
let output = content('tests/__data__/output/logs/load-cluster/cluster_1.log')
|
||||||
|
let expected = content('tests/__data__/expected/logs/load-cluster/cluster_1.log')
|
||||||
|
|
||||||
expect(Object.keys(output[0]).sort()).toEqual(['channel', 'date', 'error', 'programs'])
|
output = output.map(i => {
|
||||||
|
i.date = null
|
||||||
expect(output[0]).toMatchObject({
|
return i
|
||||||
channel: {
|
})
|
||||||
_id: '0Wefq0oMR3feCcuY',
|
expected = expected.map(i => {
|
||||||
logo: 'https://example.com/logo.png'
|
i.date = null
|
||||||
},
|
return i
|
||||||
date: dayjs.utc().startOf('d').format(),
|
|
||||||
error: null
|
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(output[1]).toMatchObject({
|
expect(output).toEqual(expected)
|
||||||
channel: {
|
|
||||||
_id: '1XzrxNkSF2AQNBrT',
|
|
||||||
logo: 'https://www.magticom.ge/images/channels/MjAxOC8wOS8xMC9lZmJhNWU5Yy0yMmNiLTRkMTAtOWY5Ny01ODM0MzY0ZTg0MmEuanBn.jpg'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function content(filepath) {
|
function content(filepath) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue