Skip to content

Commit

Permalink
celery flower service added (#366)
Browse files Browse the repository at this point in the history
* celery flower service added

* flower added to requirements

* broker url removed

* flower data persisted

* flower volume added

* volume removed

* permission denied issue resolved

* revert build changes

---------

Co-authored-by: Harsh Shah <shahharsh176@gmail.com>
  • Loading branch information
deepakdinesh1123 and shahharsh176 authored Sep 25, 2024
1 parent a36574f commit 121fc45
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
- id: check-symlinks
- id: check-toml
- id: end-of-file-fixer
exclude: frontend/
exclude: ^(frontend/|.*\.js$)
- id: requirements-txt-fixer
- id: detect-private-key
- repo: https://github.com/astral-sh/ruff-pre-commit
Expand Down
2 changes: 2 additions & 0 deletions backend/requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ django-storages==1.14
django-tenants==3.6.1
djangorestframework==3.15.2
flake8==6.1.0

flower==2.0.1
loguru==0.7.2
opentelemetry-api==1.22.0
opentelemetry-distro==0.43b0
Expand Down
1 change: 1 addition & 0 deletions deploy/dev.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ USER zango_user


COPY init.sh /zango/
COPY start_flower.sh /zango/
WORKDIR /zango/
CMD ["/bin/sh", "init.sh"]
27 changes: 26 additions & 1 deletion deploy/docker_compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@ services:
redis:
condition: service_healthy

celery-flower:
build:
context: .
dockerfile: dev.dockerfile
args:
- HOST_UID=${HOST_UID}
- HOST_GID=${HOST_GID}
restart: always
entrypoint:
- /bin/sh
- start_flower.sh
ports:
- "5555:5555"
env_file:
- .env
volumes:
- .:/zango/
environment:
- FLOWER_PORT=5555
- FLOWER_PERSISTENT=True
- FLOWER_STATE_SAVE_INTERVAL=10000
depends_on:
- postgres
- redis
- celery

redis:
image: redis
ports:
Expand All @@ -83,6 +109,5 @@ services:
redis:
condition: service_healthy


volumes:
dev_db:
26 changes: 26 additions & 0 deletions deploy/docker_compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,32 @@ services:
timeout: 5s
retries: 3

celery-flower:
build:
context: .
dockerfile: prod.dockerfile
args:
- HOST_UID=${HOST_UID}
- HOST_GID=${HOST_GID}
restart: always
entrypoint:
- /bin/sh
- start_flower.sh
ports:
- "5555:5555"
env_file:
- .env
volumes:
- .:/zango/
environment:
- FLOWER_PORT=5555
- FLOWER_PERSISTENT=True
- FLOWER_STATE_SAVE_INTERVAL=10000
depends_on:
- postgres
- redis
- celery

celery_beat:
image: kczelthy/zango:latest
command: /bin/sh -c "cd ${PROJECT_NAME} && celery -A ${PROJECT_NAME} beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler"
Expand Down
1 change: 1 addition & 0 deletions deploy/prod.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ RUN apt update && \
USER zango_user

COPY init.sh /zango/
COPY start_flower.sh /zango/
WORKDIR /zango/
CMD ["/bin/sh", "init.sh"]
9 changes: 9 additions & 0 deletions deploy/start_flower.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

cd ${PROJECT_NAME}
until timeout 5s celery -A ${PROJECT_NAME} inspect ping; do
>&2 echo "Celery workers not available"
done

echo 'Starting flower'
celery -A ${PROJECT_NAME} flower --port=5555
1 change: 1 addition & 0 deletions setup_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def load_necessary_files(project_dir, project_name, without_db):
shutil.copy("deploy/dev.dockerfile", f"{project_dir}/dev.dockerfile")
shutil.copy("deploy/prod.dockerfile", f"{project_dir}/prod.dockerfile")
shutil.copy("deploy/init.sh", f"{project_dir}/init.sh")
shutil.copy("deploy/start_flower.sh", f"{project_dir}/start_flower.sh")


def write_env_file(project_dir, args):
Expand Down

0 comments on commit 121fc45

Please sign in to comment.