#!/usr/bin/env bash # This sript is used to start the backend services and configure them according to what's available in the system set -eux if ! command -v celery &> /dev/null; then echo "Error: celery is not installed. Please install celery and try again" exit 1 fi set +e pkill -f celery pkill watchmedo set -e # use redis container instead to avoid overwriting prod # if command -v kubectl &> /dev/null; then # set +e # pkill -f "kubectl port-forward" # set -e # # kubectl port-forward $(kubectl get pods -n redis -o json | jq '.items[0].metadata.name' | sed 's/"//g') --address 0.0.0.0 6379:6379 -n redis & # fi # Ensure connection to broken is successful python celery_app.py watchmedo auto-restart --directory=./ --pattern='*.py' --recursive -- celery -A celery_app worker & # DEV to autoreload on changes CELERY_PID=$! # cleanup() { # echo "Stopping uvicorn process (PID: $UVICORN_PID)..." # kill "$UVICORN_PID" 2>/dev/null # Graceful shutdown (SIGTERM) # wait "$UVICORN_PID" 2>/dev/null # Wait for process to exit # echo "Stopping background process (PID: $CELERY_PID)..." # kill "$CELERY_PID" 2>/dev/null # Graceful shutdown (SIGTERM) # wait "$CELERY_PID" 2>/dev/null # Wait for process to exit # } # trap cleanup EXIT SIGINT SIGTERM # celery -A celery_app worker -D # PROD uvicorn api.app:app --host 0.0.0.0 --port 5001 --reload --reload-exclude "data" --log-level debug # UVICORN_PID=$! # wait for # less /etc/passwd > /dev/null