mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-12 18:10:04 -04:00
Rename to cluster/load.js
This commit is contained in:
parent
c03095f762
commit
97b9421cb1
4 changed files with 4 additions and 4 deletions
|
@ -1,51 +0,0 @@
|
|||
const { db, logger, timer, checker, store, file, parser } = require('../../core')
|
||||
const { program } = require('commander')
|
||||
|
||||
const options = program
|
||||
.requiredOption('-c, --cluster-id <cluster-id>', 'The ID of cluster to load', parser.parseNumber)
|
||||
.option('-t, --timeout <timeout>', 'Set timeout for each request', parser.parseNumber, 60000)
|
||||
.option('-d, --delay <delay>', 'Set delay for each request', parser.parseNumber, 0)
|
||||
.option('--debug', 'Enable debug mode')
|
||||
.parse(process.argv)
|
||||
.opts()
|
||||
|
||||
const config = {
|
||||
timeout: options.timeout,
|
||||
delay: options.delay,
|
||||
debug: options.debug
|
||||
}
|
||||
|
||||
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs/stream/load'
|
||||
|
||||
async function main() {
|
||||
logger.info('starting...')
|
||||
logger.info(`timeout: ${options.timeout}ms`)
|
||||
logger.info(`delay: ${options.delay}ms`)
|
||||
timer.start()
|
||||
|
||||
const clusterLog = `${LOGS_DIR}/cluster_${options.clusterId}.log`
|
||||
logger.info(`loading cluster: ${options.clusterId}`)
|
||||
logger.info(`creating '${clusterLog}'...`)
|
||||
await file.create(clusterLog)
|
||||
await db.streams.load()
|
||||
const items = await db.streams.find({ cluster_id: options.clusterId })
|
||||
const total = items.length
|
||||
logger.info(`found ${total} links`)
|
||||
|
||||
logger.info('checking...')
|
||||
const results = {}
|
||||
for (const [i, item] of items.entries()) {
|
||||
const message = `[${i + 1}/${total}] ${item.filepath}: ${item.url}`
|
||||
const result = await checker.check(item, config)
|
||||
if (!result.error) {
|
||||
logger.info(message)
|
||||
} else {
|
||||
logger.info(`${message} (${result.error})`)
|
||||
}
|
||||
await file.append(clusterLog, JSON.stringify(result) + '\n')
|
||||
}
|
||||
|
||||
logger.info(`done in ${timer.format('HH[h] mm[m] ss[s]')}`)
|
||||
}
|
||||
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue