Files
maps-saas/scripts/master_cron_sync.sh
T

55 lines
2.4 KiB
Bash

#!/bin/bash
# ==============================================================================
# SIRO Maps — Master Bi-Monthly Geospatial Synchronization (Every 15 Days)
# ==============================================================================
# This script runs automatically via crontab on the 1st and 15th of every month.
# It checks and syncs:
# 1. OpenStreetMap & Overture Maps for Jordan, Iraq, Syria, and Egypt.
# 2. Gate & Entrance mapping (Hospitals, Malls, Universities, Hotels, Parks).
# 3. Administrative boundary resolution (Governorates & Districts).
# 4. Materialized view concurrent refresh (unified_search_index).
# 5. Redis search cache flushing.
# ==============================================================================
set -euo pipefail
APP_DIR="${APP_DIR:-/home/hamzadoctor/app}"
LOG_DIR="${APP_DIR}/logs"
LOG_FILE="${LOG_DIR}/cron_places_sync.log"
mkdir -p "$LOG_DIR"
echo "==============================================================================" >> "$LOG_FILE"
echo "📅 [$(date '+%Y-%m-%d %H:%M:%S')] Starting Bi-Monthly SIRO Maps Sync" >> "$LOG_FILE"
echo "==============================================================================" >> "$LOG_FILE"
cd "$APP_DIR"
# 1. Sync Iraq
echo "🇮🇶 Syncing Iraq places..." >> "$LOG_FILE"
python3 -u scripts/enrich_iraq_comprehensive.py >> "$LOG_FILE" 2>&1 || echo "⚠️ Iraq sync had warnings" >> "$LOG_FILE"
# 2. Sync Egypt
echo "🇪🇬 Syncing Egypt places..." >> "$LOG_FILE"
python3 -u scripts/enrich_egypt_places.py >> "$LOG_FILE" 2>&1 || echo "⚠️ Egypt sync had warnings" >> "$LOG_FILE"
# 3. Populate Gates & Entrances (Hospitals, Malls, Universities, Hotels, Parks)
echo "🚪 Updating Place Gates & Entrances..." >> "$LOG_FILE"
python3 -u scripts/populate_place_gates.py --country all >> "$LOG_FILE" 2>&1 || echo "⚠️ Gates update had warnings" >> "$LOG_FILE"
# 4. Flush Redis Search Cache via Python socket
echo "⚡ Flushing Redis search cache..." >> "$LOG_FILE"
python3 -c "
import socket
try:
s = socket.socket()
s.connect(('127.0.0.1', 6381))
s.sendall(b'FLUSHDB\r\n')
print('Redis FLUSHDB:', s.recv(1024).decode().strip())
except Exception as e:
print('Redis flush error:', e)
" >> "$LOG_FILE" 2>&1
echo "✅ [$(date '+%Y-%m-%d %H:%M:%S')] Bi-Monthly Sync Completed Successfully!" >> "$LOG_FILE"
echo "==============================================================================" >> "$LOG_FILE"