2025-10-07 14:52:04 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# ParentZone Downloaders Daily Scheduler
|
|
|
|
|
# This script runs both the config downloader and snapshot downloader
|
|
|
|
|
|
2025-10-14 21:58:54 +01:00
|
|
|
LOG_DIR="/app/data/logs"
|
2025-10-07 14:52:04 +01:00
|
|
|
LOG_FILE="$LOG_DIR/scheduler_$(date +%Y%m%d).log"
|
2025-10-14 21:58:54 +01:00
|
|
|
SNAPSHOT_CONFIG_FILE="/app/config/snapshot_config.json"
|
|
|
|
|
ASSET_CONFIG_FILE="/app/config/parentzone_config.json"
|
2025-10-07 14:52:04 +01:00
|
|
|
|
|
|
|
|
# Create log directory if it doesn't exist
|
|
|
|
|
mkdir -p "$LOG_DIR"
|
|
|
|
|
|
|
|
|
|
# Function to log messages with timestamp
|
|
|
|
|
log_message() {
|
|
|
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Function to run a command and log its output
|
|
|
|
|
run_with_logging() {
|
|
|
|
|
local command="$1"
|
|
|
|
|
local description="$2"
|
|
|
|
|
|
|
|
|
|
log_message "Starting: $description"
|
|
|
|
|
log_message "Command: $command"
|
|
|
|
|
|
|
|
|
|
# Run the command and capture both stdout and stderr
|
|
|
|
|
if eval "$command" >> "$LOG_FILE" 2>&1; then
|
|
|
|
|
log_message "SUCCESS: $description completed successfully"
|
|
|
|
|
return 0
|
|
|
|
|
else
|
|
|
|
|
log_message "ERROR: $description failed with exit code $?"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Main execution
|
|
|
|
|
log_message "=== ParentZone Downloaders Daily Run Started ==="
|
|
|
|
|
|
2025-10-09 22:41:14 +01:00
|
|
|
# Check if config files exist
|
|
|
|
|
if [ ! -f "$SNAPSHOT_CONFIG_FILE" ]; then
|
|
|
|
|
log_message "ERROR: Snapshot configuration file $SNAPSHOT_CONFIG_FILE not found"
|
2025-10-07 14:52:04 +01:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2025-10-09 22:41:14 +01:00
|
|
|
if [ ! -f "$ASSET_CONFIG_FILE" ]; then
|
|
|
|
|
log_message "WARNING: Asset configuration file $ASSET_CONFIG_FILE not found, skipping asset downloader"
|
|
|
|
|
SKIP_ASSET_DOWNLOADER=true
|
|
|
|
|
else
|
|
|
|
|
SKIP_ASSET_DOWNLOADER=false
|
|
|
|
|
fi
|
|
|
|
|
|
2025-10-07 14:52:04 +01:00
|
|
|
cd /app
|
|
|
|
|
|
2025-10-09 22:41:14 +01:00
|
|
|
# Run config-based asset downloader
|
|
|
|
|
if [ "$SKIP_ASSET_DOWNLOADER" = false ]; then
|
2025-10-14 21:58:54 +01:00
|
|
|
run_with_logging "python3 src/config_downloader.py --config $ASSET_CONFIG_FILE" "Config Asset Downloader"
|
2025-10-09 22:41:14 +01:00
|
|
|
asset_result=$?
|
|
|
|
|
else
|
|
|
|
|
log_message "SKIPPED: Config Asset Downloader (configuration file not found)"
|
|
|
|
|
asset_result=0
|
|
|
|
|
fi
|
|
|
|
|
|
2025-10-07 14:52:04 +01:00
|
|
|
# Run config-based snapshot downloader
|
2025-10-14 21:58:54 +01:00
|
|
|
run_with_logging "python3 src/config_snapshot_downloader.py --config $SNAPSHOT_CONFIG_FILE" "Config Snapshot Downloader"
|
2025-10-07 14:52:04 +01:00
|
|
|
config_result=$?
|
|
|
|
|
|
|
|
|
|
# Summary
|
|
|
|
|
log_message "=== Daily Run Summary ==="
|
2025-10-09 22:41:14 +01:00
|
|
|
if [ "$SKIP_ASSET_DOWNLOADER" = false ]; then
|
|
|
|
|
if [ $asset_result -eq 0 ]; then
|
|
|
|
|
log_message "✓ Config Asset Downloader: SUCCESS"
|
|
|
|
|
else
|
|
|
|
|
log_message "✗ Config Asset Downloader: FAILED"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
log_message "- Config Asset Downloader: SKIPPED"
|
|
|
|
|
fi
|
|
|
|
|
|
2025-10-07 14:52:04 +01:00
|
|
|
if [ $config_result -eq 0 ]; then
|
|
|
|
|
log_message "✓ Config Snapshot Downloader: SUCCESS"
|
|
|
|
|
else
|
|
|
|
|
log_message "✗ Config Snapshot Downloader: FAILED"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ $snapshot_result -eq 0 ]; then
|
|
|
|
|
log_message "✓ Snapshot Downloader: SUCCESS"
|
|
|
|
|
else
|
|
|
|
|
log_message "✗ Snapshot Downloader: FAILED"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Cleanup old log files (keep only last 30 days)
|
|
|
|
|
find "$LOG_DIR" -name "scheduler_*.log" -mtime +30 -delete 2>/dev/null || true
|
|
|
|
|
|
|
|
|
|
log_message "=== ParentZone Downloaders Daily Run Completed ==="
|
|
|
|
|
|
|
|
|
|
# Exit with error if any downloader failed
|
2025-10-09 22:41:14 +01:00
|
|
|
if [ $asset_result -ne 0 ] || [ $config_result -ne 0 ] || [ $snapshot_result -ne 0 ]; then
|
2025-10-07 14:52:04 +01:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
exit 0
|