#!/bin/bash ulimit -n 97816 # Load Redis password from .env file export REDIS_PASSWORD=$(grep -m 1 'REDIS_PASSWORD' .env | cut -d '=' -f2) # Color definitions for log messages GREEN='\033[0;32m' YELLOW='\033[0;33m' RED='\033[0;31m' NC='\033[0m' # No Color # Function to print log messages with colors log_info() { echo -e "${GREEN}[INFO] $1${NC}" } log_warning() { echo -e "${YELLOW}[WARNING] $1${NC}" } log_error() { echo -e "${RED}[ERROR] $1${NC}" } # Start clearing Redis locks log_info "Clearing Redis locks..." # Check if Redis password was set correctly if [ -z "$REDIS_PASSWORD" ]; then log_error "REDIS_PASSWORD not set. Please check your .env file." exit 1 fi # Deleting keys and getting the total deleted count TOTAL_DELETED_KEYS=$(redis-cli -a "$REDIS_PASSWORD" --scan --pattern '*_lock' 2>/dev/null | \ xargs -I {} redis-cli -a "$REDIS_PASSWORD" del {} 2>/dev/null | wc -l) # Log the result if [ "$TOTAL_DELETED_KEYS" -gt 0 ]; then log_info "Total deleted keys: $TOTAL_DELETED_KEYS" else log_warning "No keys matched the pattern '*_lock'." fi # Clear RabbitMQ queue log_info "Purging RabbitMQ queue 'taskiq' in vhost 'stocks_vhost'..." rabbitmqctl purge_queue -p stocks_vhost taskiq if [ $? -eq 0 ]; then log_info "RabbitMQ queue purged successfully." else log_error "Failed to purge RabbitMQ queue. Please check your RabbitMQ setup." fi # Start the Taskiq worker log_info "Starting Taskiq worker..." taskiq worker background:taskiq_broker background.tasks --max-async-task 5000 --max-threadpool-threads 8 --max-prefetch 10000 # Log when the Taskiq worker stops log_info "Taskiq worker stopped"