Files
parentzone_downloader/scheduler.sh

88 lines
2.6 KiB
Bash
Raw Normal View History

2025-10-07 14:52:04 +01:00
#!/bin/bash
# ParentZone Downloaders Daily Scheduler
# This script runs both the config downloader and snapshot downloader
LOG_DIR="/app/logs"
LOG_FILE="$LOG_DIR/scheduler_$(date +%Y%m%d).log"
2025-10-09 22:16:15 +01:00
CONFIG_FILE="/app/snapshot_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 ==="
# Check if config file exists
if [ ! -f "$CONFIG_FILE" ]; then
log_message "ERROR: Configuration file $CONFIG_FILE not found"
exit 1
fi
cd /app
# Run config-based snapshot downloader
run_with_logging "python3 config_snapshot_downloader.py --config $CONFIG_FILE" "Config Snapshot Downloader"
config_result=$?
# Run regular snapshot downloader with environment variables
if [ -n "$API_KEY" ]; then
run_with_logging "python3 snapshot_downloader.py --api-key $API_KEY --output-dir snapshots" "Snapshot Downloader (API Key)"
snapshot_result=$?
elif [ -n "$EMAIL" ] && [ -n "$PASSWORD" ]; then
run_with_logging "python3 snapshot_downloader.py --email $EMAIL --password $PASSWORD --output-dir snapshots" "Snapshot Downloader (Email/Password)"
snapshot_result=$?
else
log_message "WARNING: No authentication method provided via environment variables, skipping direct snapshot downloader"
snapshot_result=0
fi
# Summary
log_message "=== Daily Run Summary ==="
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
if [ $config_result -ne 0 ] || [ $snapshot_result -ne 0 ]; then
exit 1
fi
exit 0