#!/bin/bash # Insurance Plan Processor Cron Script # This script runs the insurance plan processor from within the Docker container # Set script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" # Log file for cron output LOG_FILE="$PROJECT_DIR/logs/insurance_processor.log" ERROR_LOG_FILE="$PROJECT_DIR/logs/insurance_processor_error.log" # Create logs directory if it doesn't exist mkdir -p "$(dirname "$LOG_FILE")" # Function to log messages log_message() { echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE" } log_error() { echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR: $1" | tee -a "$ERROR_LOG_FILE" } # Log start of execution log_message "Starting insurance plan processor..." # Check if Docker Compose is running if ! docker compose ps --services --filter "status=running" | grep -q "lolly-api"; then log_error "Docker Compose service 'lolly-api' is not running" exit 1 fi # Change to project directory cd "$PROJECT_DIR" || { log_error "Failed to change to project directory: $PROJECT_DIR" exit 1 } # Run the insurance plan processor log_message "Executing insurance plan processor..." if docker compose exec -T lolly-api uv run python ./src/insurance_plan_processor.py; then log_message "Insurance plan processor completed successfully" exit 0 else log_error "Insurance plan processor failed with exit code $?" exit 1 fi