A Django application with Celery task queue integration, using PostgreSQL and RabbitMQ.
- Clone and Setup Environment
git clone <repository-url>
cd <repository-name>
conda env create -f environment.yml
conda activate test-app
- Configure Environment
Copy the
.env.template
file to create your.env
:
cp .env.template .env
Then modify the values in .env
according to your needs.
- Configure PostgreSQL
# First-time setup
mkdir -p $CONDA_PREFIX/var/{postgres,run/postgresql}
initdb -D $CONDA_PREFIX/var/postgres
echo "unix_socket_directories = '$CONDA_PREFIX/var/run/postgresql'" >> $CONDA_PREFIX/var/postgres/postgresql.conf
# Start PostgreSQL
pg_ctl -D $CONDA_PREFIX/var/postgres start
# Create database and user
export $(cat .env | grep -v '^#' | xargs)
createdb -h $CONDA_PREFIX/var/run/postgresql $POSTGRES_DB
psql -h $CONDA_PREFIX/var/run/postgresql -d $POSTGRES_DB << EOF
CREATE USER $POSTGRES_USER WITH PASSWORD '$POSTGRES_PASSWORD';
ALTER USER $POSTGRES_USER WITH CREATEDB;
GRANT ALL PRIVILEGES ON DATABASE $POSTGRES_DB TO $POSTGRES_USER;
GRANT ALL ON SCHEMA public TO $POSTGRES_USER;
ALTER SCHEMA public OWNER TO $POSTGRES_USER;
EOF
- Run the Application
In separate terminals (with
conda activate test-app
):
# Terminal 1: RabbitMQ
rabbitmq-server
# Terminal 2: Django
python manage.py migrate
python manage.py runserver
# Terminal 3: Celery
celery -A app worker -l INFO -c 1
Access the application:
- Django: http://localhost:8000
- RabbitMQ Management: http://localhost:15672 (guest/guest)