This commit is contained in:
@@ -98,27 +98,34 @@ if [ -n "$CRON_SCHEDULE" ] && [ -n "$SITES" ]; then
|
|||||||
# Create a script to grab all sites concurrently
|
# Create a script to grab all sites concurrently
|
||||||
cat >/app/grab-sites.js <<EOL
|
cat >/app/grab-sites.js <<EOL
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const { execSync } = require('child_process');
|
|
||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
const sites = process.env.SITES.split(',').filter(site => site.trim() !== '');
|
|
||||||
|
// Store environment variables at the beginning
|
||||||
|
const envSites = process.env.SITES || '';
|
||||||
|
const maxConnections = process.env.MAX_CONNECTIONS || 1;
|
||||||
|
const days = process.env.DAYS;
|
||||||
|
const delay = process.env.DELAY;
|
||||||
|
const lang = process.env.LANG;
|
||||||
|
const gzip = process.env.GZIP === 'true';
|
||||||
|
|
||||||
|
const sites = envSites.split(',').filter(site => site.trim() !== '');
|
||||||
|
|
||||||
console.log(\`Starting scheduled EPG grab at \${new Date().toISOString()}\`);
|
console.log(\`Starting scheduled EPG grab at \${new Date().toISOString()}\`);
|
||||||
|
|
||||||
// Track running processes
|
// Track running processes
|
||||||
const processes = [];
|
|
||||||
let completedCount = 0;
|
let completedCount = 0;
|
||||||
|
|
||||||
sites.forEach(site => {
|
sites.forEach(site => {
|
||||||
try {
|
try {
|
||||||
console.log(\`Starting grab for site: \${site}\`);
|
console.log(\`Starting grab for site: \${site}\`);
|
||||||
let cmd = 'npm';
|
let cmd = 'npm';
|
||||||
let args = ['run', 'grab', '--', \`--site=\${site}\`, \`--output=output/\${site}.xml\`, \`--maxConnections=\${process.env.MAX_CONNECTIONS || 1}\`];
|
let args = ['run', 'grab', '--', \`--site=\${site}\`, \`--output=output/\${site}.xml\`, \`--maxConnections=\${maxConnections}\`];
|
||||||
|
|
||||||
// Add optional parameters
|
// Add optional parameters
|
||||||
if (process.env.DAYS) args.push(\`--days=\${process.env.DAYS}\`);
|
if (days) args.push(\`--days=\${days}\`);
|
||||||
if (process.env.DELAY) args.push(\`--delay=\${process.env.DELAY}\`);
|
if (delay) args.push(\`--delay=\${delay}\`);
|
||||||
if (process.env.LANG) args.push(\`--lang=\${process.env.LANG}\`);
|
if (lang) args.push(\`--lang=\${lang}\`);
|
||||||
if (process.env.GZIP === 'true') args.push('--gzip');
|
if (gzip) args.push('--gzip');
|
||||||
|
|
||||||
const process = spawn(cmd, args, { stdio: 'inherit' });
|
const process = spawn(cmd, args, { stdio: 'inherit' });
|
||||||
|
|
||||||
@@ -134,8 +141,6 @@ sites.forEach(site => {
|
|||||||
console.log(\`Completed scheduled EPG grab at \${new Date().toISOString()}\`);
|
console.log(\`Completed scheduled EPG grab at \${new Date().toISOString()}\`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
processes.push(process);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(\`Error starting EPG grab for site: \${site}\`, error);
|
console.error(\`Error starting EPG grab for site: \${site}\`, error);
|
||||||
completedCount++;
|
completedCount++;
|
||||||
|
|||||||
Reference in New Issue
Block a user