add insurance processor script
This commit is contained in:
parent
4f82307cd9
commit
bf1d988d36
21 changed files with 372 additions and 1552 deletions
110
scripts/README.md
Normal file
110
scripts/README.md
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
# Insurance Plan Processor Cron Setup
|
||||
|
||||
This directory contains scripts for running the insurance plan processor as a scheduled task.
|
||||
|
||||
## Files
|
||||
|
||||
- `run_insurance_processor.sh` - Main script to run the insurance plan processor from within the Docker container
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
### 1. Test the Script
|
||||
|
||||
First, test that the script works correctly:
|
||||
|
||||
```bash
|
||||
./scripts/run_insurance_processor.sh
|
||||
```
|
||||
|
||||
### 2. Set up Cron Job
|
||||
|
||||
Add a cron job to run the script at your desired interval. For example, to run it daily at 2 AM:
|
||||
|
||||
```bash
|
||||
# Open crontab for editing
|
||||
crontab -e
|
||||
|
||||
# Add one of these lines depending on your needs:
|
||||
|
||||
# Run daily at 2 AM
|
||||
0 2 * * * /path/to/lolly-ai/scripts/run_insurance_processor.sh
|
||||
|
||||
# Run every 6 hours
|
||||
0 */6 * * * /path/to/lolly-ai/scripts/run_insurance_processor.sh
|
||||
|
||||
# Run every hour
|
||||
0 * * * * /path/to/lolly-ai/scripts/run_insurance_processor.sh
|
||||
|
||||
# Run every 30 minutes
|
||||
*/30 * * * * /path/to/lolly-ai/scripts/run_insurance_processor.sh
|
||||
```
|
||||
|
||||
### 3. Verify Cron Job
|
||||
|
||||
Check that your cron job was added correctly:
|
||||
|
||||
```bash
|
||||
crontab -l
|
||||
```
|
||||
|
||||
### 4. Monitor Logs
|
||||
|
||||
The script creates logs in the `logs/` directory:
|
||||
|
||||
- `logs/insurance_processor.log` - General execution logs
|
||||
- `logs/insurance_processor_error.log` - Error logs
|
||||
|
||||
Monitor these files to ensure the script is running correctly:
|
||||
|
||||
```bash
|
||||
# View recent logs
|
||||
tail -f logs/insurance_processor.log
|
||||
|
||||
# View error logs
|
||||
tail -f logs/insurance_processor_error.log
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Docker Compose must be running with the `lolly-ai` service
|
||||
- The `.env` file must be properly configured with API keys
|
||||
- The script must have execute permissions (`chmod +x scripts/run_insurance_processor.sh`)
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **Docker service not running**: The script checks if the Docker Compose service is running and will log an error if it's not.
|
||||
|
||||
2. **Permission denied**: Make sure the script is executable:
|
||||
```bash
|
||||
chmod +x scripts/run_insurance_processor.sh
|
||||
```
|
||||
|
||||
3. **Path issues**: Make sure to use the full path to the script in your cron job.
|
||||
|
||||
4. **Environment variables**: The script uses the `.env` file from the project directory, so make sure it's properly configured.
|
||||
|
||||
### Debugging
|
||||
|
||||
To debug cron issues, you can temporarily run the script manually and check the logs:
|
||||
|
||||
```bash
|
||||
# Run manually
|
||||
./scripts/run_insurance_processor.sh
|
||||
|
||||
# Check logs
|
||||
cat logs/insurance_processor.log
|
||||
cat logs/insurance_processor_error.log
|
||||
```
|
||||
|
||||
## Cron Schedule Examples
|
||||
|
||||
| Schedule | Description |
|
||||
|----------|-------------|
|
||||
| `0 2 * * *` | Daily at 2 AM |
|
||||
| `0 */6 * * *` | Every 6 hours |
|
||||
| `0 * * * *` | Every hour |
|
||||
| `*/30 * * * *` | Every 30 minutes |
|
||||
| `0 2 * * 1` | Every Monday at 2 AM |
|
||||
| `0 2 1 * *` | First day of each month at 2 AM |
|
||||
50
scripts/run_insurance_processor.sh
Executable file
50
scripts/run_insurance_processor.sh
Executable file
|
|
@ -0,0 +1,50 @@
|
|||
#!/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
|
||||
Loading…
Add table
Add a link
Reference in a new issue