Adds option to change the delay between requests

This commit is contained in:
freearhey 2023-10-19 20:22:02 +03:00
parent 5478aa2b24
commit b1bcc08591
3 changed files with 8 additions and 0 deletions

View file

@ -57,6 +57,7 @@ Options:
-o, --output <path> Path to output file (default: "guide.xml") -o, --output <path> Path to output file (default: "guide.xml")
-l, --lang <code> Filter channels by language (ISO 639-2 code) -l, --lang <code> Filter channels by language (ISO 639-2 code)
-t, --timeout <milliseconds> Override the default timeout for each request -t, --timeout <milliseconds> Override the default timeout for each request
-d, --delay <milliseconds> Override the default delay between request
--days <days> Override the number of days for which the program will be loaded --days <days> Override the number of days for which the program will be loaded
(defaults to the value from the site config) (defaults to the value from the site config)
--maxConnections <number> Limit on the number of concurrent requests (default: 1) --maxConnections <number> Limit on the number of concurrent requests (default: 1)

View file

@ -15,6 +15,7 @@ program
.option('-o, --output <path>', 'Path to output file', 'guide.xml') .option('-o, --output <path>', 'Path to output file', 'guide.xml')
.option('-l, --lang <code>', 'Filter channels by language (ISO 639-2 code)') .option('-l, --lang <code>', 'Filter channels by language (ISO 639-2 code)')
.option('-t, --timeout <milliseconds>', 'Override the default timeout for each request') .option('-t, --timeout <milliseconds>', 'Override the default timeout for each request')
.option('-d, --delay <milliseconds>', 'Override the default delay between request')
.option( .option(
'--days <days>', '--days <days>',
'Override the number of days for which the program will be loaded (defaults to the value from the site config)', 'Override the number of days for which the program will be loaded (defaults to the value from the site config)',
@ -37,6 +38,7 @@ export type GrabOptions = {
gzip: boolean gzip: boolean
maxConnections: number maxConnections: number
timeout?: string timeout?: string
delay?: string
lang?: string lang?: string
days?: number days?: number
cron?: string cron?: string

View file

@ -43,6 +43,11 @@ export class Grabber {
config.request = { ...config.request, ...{ timeout } } config.request = { ...config.request, ...{ timeout } }
} }
if (this.options.delay !== undefined) {
const delay = parseInt(this.options.delay)
config.delay = delay
}
const grabber = const grabber =
process.env.NODE_ENV === 'test' ? new EPGGrabberMock(config) : new EPGGrabber(config) process.env.NODE_ENV === 'test' ? new EPGGrabberMock(config) : new EPGGrabber(config)
const _programs = await grabber.grab( const _programs = await grabber.grab(