Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

celery flower service added #366

Merged
merged 8 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we run docker-compose down and then docker-compose up, the previous Flower data is lost. We need to use persistent volume to retain the data.

- .:/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