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