Skip to content

Commit be351f8

Browse files
committed
feat: add health check; fix: rabbitmq credentials, minio ci set up
1 parent 875d3cb commit be351f8

File tree

9 files changed

+74
-45
lines changed

9 files changed

+74
-45
lines changed

.envs/.ci/.postgres

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ POSTGRES_PORT=5432
33
POSTGRES_DB=ami-ci
44
POSTGRES_USER=4JXkOnTAeDmDyIapSRrGEE
55
POSTGRES_PASSWORD=d4xojpnJU3OzPQ0apSCLP1oHR1TYvyMzAlF5KpE9HFL6MPlnbDibwI
6+
DATABASE_URL=postgres://xekSryPnqczJXkOnTAeDmDyIapSRrGEE:iMRQjJEGflj5xojpnJU3OzPQ0apSCLP1oHR1TYvyMzAlF5KpE9HFL6MPlnbDibwI@postgres:5432/ami

.envs/.local/.django

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ DJANGO_SUPERUSER_PASSWORD=localadmin
1212
# Redis
1313
REDIS_URL=redis://redis:6379/0
1414

15-
# RabbitMQ
16-
CELERY_BROKER_URL=amqp://user:password@rabbitmq:5672//
17-
1815
# Celery / Flower
1916
CELERY_FLOWER_USER=QSocnxapfMvzLqJXSsXtnEZqRkBtsmKT
2017
CELERY_FLOWER_PASSWORD=BEQgmCtgyrFieKNoGTsux9YIye0I7P5Q7vEgfJD2C4jxmtHDetFaE2jhS7K7rxaf

.envs/.local/.postgres

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ POSTGRES_PORT=5432
33
POSTGRES_DB=ami
44
POSTGRES_USER=xekSryPnqczJXkOnTAeDmDyIapSRrGEE
55
POSTGRES_PASSWORD=iMRQjJEGflj5xojpnJU3OzPQ0apSCLP1oHR1TYvyMzAlF5KpE9HFL6MPlnbDibwI
6+
DATABASE_URL=postgres://xekSryPnqczJXkOnTAeDmDyIapSRrGEE:iMRQjJEGflj5xojpnJU3OzPQ0apSCLP1oHR1TYvyMzAlF5KpE9HFL6MPlnbDibwI@postgres:5432/ami

ami/ml/models/pipeline.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ def handle_async_process_images(
334334
)
335335

336336
task_id = str(uuid.uuid4())
337+
# use transaction on commit to ensure source images and other project details are finished saving
337338
transaction.on_commit(
338339
lambda: process_pipeline_request.apply_async(
339340
args=[prediction_request.dict(), project_id],

ami/ml/signals.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,7 @@ def subscribe_celeryworker_to_pipeline_queues(sender, **kwargs) -> bool:
5454
if not pipelines:
5555
# TODO: kinda hacky. is there a way to unify the django and celery logs
5656
# to more easily see which queues the worker is subscribed to?
57-
raise ValueError(
58-
"No pipelines found; cannot subscribe to any queues. "
59-
"If the database was just reset and migrated, this error might be expected. "
60-
"Check both django and celery logs to ensure worker is subscribed to the project queues. "
61-
"Alternatively, restart the celery worker again."
62-
)
57+
raise ValueError("No pipelines found; cannot subscribe to any queues.")
6358

6459
for slug in pipelines:
6560
queue_name = f"ml-pipeline-{slug}"
@@ -81,13 +76,11 @@ def pipeline_created(sender, instance, created, **kwargs):
8176
queue_name = f"ml-pipeline-{instance.slug}"
8277
worker_name = get_worker_name()
8378

84-
if not worker_name:
85-
logger.warning(
86-
"Could not determine worker name; cannot subscribe to new queue "
87-
f"{queue_name}. This might be an expected error if the worker hasn't "
88-
"started or is ready to accept connections."
89-
)
90-
return
79+
assert worker_name, (
80+
"Could not determine worker name; cannot subscribe to new queue "
81+
f"{queue_name}. This might be an expected error if the worker hasn't "
82+
"started or is ready to accept connections."
83+
)
9184

9285
celery_app.control.add_consumer(queue_name, destination=[worker_name])
9386
logger.info(f"Queue '{queue_name}' successfully added to worker '{worker_name}'")

compose/local/django/Dockerfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ RUN sed -i 's/\r$//g' /start
6262
RUN chmod +x /start
6363

6464

65-
COPY ./compose/local/django/celery/worker/start /start-celeryworker
66-
RUN sed -i 's/\r$//g' /start-celeryworker
67-
RUN chmod +x /start-celeryworker
68-
6965
COPY ./compose/local/django/celery/beat/start /start-celerybeat
7066
RUN sed -i 's/\r$//g' /start-celerybeat
7167
RUN chmod +x /start-celerybeat

docker-compose.ci.yml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ name: antenna-ci
44
volumes:
55
ami_ci_postgres_data:
66
driver: local
7+
minio_ci_data:
8+
driver: local
79

810
services:
911
django: &django
@@ -12,12 +14,19 @@ services:
1214
dockerfile: ./compose/local/django/Dockerfile
1315
volumes:
1416
- .:/app:z
17+
extra_hosts:
18+
- "host.docker.internal:host-gateway"
1519
depends_on:
16-
- postgres
17-
- redis
18-
- minio-init
19-
- ml_backend
20-
- celeryworker
20+
postgres:
21+
condition: service_started
22+
redis:
23+
condition: service_started
24+
minio-init:
25+
condition: service_started
26+
rabbitmq:
27+
condition: service_started
28+
celeryworker: # required to subscribe the worker to the pipelines in the db
29+
condition: service_healthy
2130
env_file:
2231
- ./.envs/.ci/.django
2332
- ./.envs/.ci/.postgres
@@ -38,11 +47,21 @@ services:
3847
celeryworker:
3948
<<: *django
4049
depends_on:
41-
- postgres
4250
- rabbitmq
43-
volumes:
44-
- ./compose/local/django/celery/worker/start:/start-celeryworker
45-
command: /start-celeryworker
51+
# start the worker with antenna_celeryworker to ensure it's discoverable by ami.ml.signals.get_worker_name
52+
command:
53+
- sh
54+
- -c
55+
- |
56+
python manage.py migrate &&
57+
python -m celery -A config.celery_app worker --queues=antenna -n antenna_celeryworker@%h -l INFO
58+
healthcheck:
59+
# make sure DATABASE_URL is inside the ./.envs/.ci/.postgres
60+
test: ["CMD-SHELL", "celery -A config.celery_app inspect ping -d antenna_celeryworker@$(hostname) | grep -q pong"]
61+
interval: 10s
62+
timeout: 50s
63+
retries: 5
64+
start_period: 10s
4665

4766
rabbitmq:
4867
image: rabbitmq:3-management
@@ -52,6 +71,8 @@ services:
5271
minio:
5372
image: minio/minio:RELEASE.2024-11-07T00-52-20Z
5473
command: minio server --console-address ":9001" /data
74+
volumes:
75+
- "minio_ci_data:/data"
5576
env_file:
5677
- ./.envs/.ci/.django
5778
healthcheck:
@@ -65,7 +86,8 @@ services:
6586
env_file:
6687
- ./.envs/.ci/.django
6788
depends_on:
68-
- minio
89+
minio:
90+
condition: service_healthy
6991
volumes:
7092
- ./compose/local/minio/init.sh:/etc/minio/init.sh
7193
entrypoint: /etc/minio/init.sh

docker-compose.yml

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ services:
2020
extra_hosts:
2121
- "host.docker.internal:host-gateway"
2222
depends_on:
23-
- postgres
24-
- redis
25-
- minio-init
26-
- rabbitmq
27-
- celeryworker # required to subscribe the worker to the pipelines in the db
23+
postgres:
24+
condition: service_started
25+
redis:
26+
condition: service_started
27+
minio-init:
28+
condition: service_started
29+
rabbitmq:
30+
condition: service_started
31+
celeryworker: # required to subscribe the worker to the pipelines in the db
32+
condition: service_healthy
2833
volumes:
2934
- .:/app:z
3035
env_file:
@@ -99,11 +104,22 @@ services:
99104
# Also make sure to install debugpy in your requirements/local.txt
100105
ports:
101106
- "5678:5678"
102-
command: python -m debugpy --listen 0.0.0.0:5678 -m celery -A config.celery_app worker --queues=antenna -n antenna_celeryworker@%h -l INFO
103-
volumes:
104-
- ./compose/local/django/celery/worker/start:/start-celeryworker
107+
# start the worker with antenna_celeryworker to ensure it's discoverable by ami.ml.signals.get_worker_name
108+
command:
109+
- sh
110+
- -c
111+
- |
112+
python manage.py migrate &&
113+
python -m debugpy --listen 0.0.0.0:5678 -m celery -A config.celery_app worker --queues=antenna -n antenna_celeryworker@%h -l INFO
105114
depends_on:
106115
- rabbitmq
116+
healthcheck:
117+
# make sure DATABASE_URL is inside the ./.envs/.local/.postgres
118+
test: ["CMD-SHELL", "celery -A config.celery_app inspect ping -d antenna_celeryworker@$(hostname) | grep -q pong"]
119+
interval: 10s
120+
timeout: 50s
121+
retries: 5
122+
start_period: 10s
107123

108124
celerybeat:
109125
<<: *django
@@ -126,8 +142,8 @@ services:
126142
- "5672:5672"
127143
- "15672:15672"
128144
environment:
129-
RABBITMQ_DEFAULT_USER: user
130-
RABBITMQ_DEFAULT_PASS: password
145+
RABBITMQ_DEFAULT_USER: rabbituser
146+
RABBITMQ_DEFAULT_PASS: rabbitpass
131147
networks:
132148
- antenna_network
133149

@@ -162,8 +178,10 @@ services:
162178
env_file:
163179
- ./.envs/.local/.django
164180
depends_on:
165-
- minio
166-
- minio-proxy
181+
minio:
182+
condition: service_healthy
183+
minio-proxy:
184+
condition: service_started
167185
volumes:
168186
- ./compose/local/minio/init.sh:/etc/minio/init.sh
169187
entrypoint: /etc/minio/init.sh
@@ -187,7 +205,7 @@ services:
187205
context: ./processing_services/minimal
188206
command: ./celery_worker/start_celery.sh
189207
environment:
190-
- CELERY_BROKER_URL=amqp://user:password@rabbitmq:5672//
208+
- CELERY_BROKER_URL=amqp://rabbituser:rabbitpass@rabbitmq:5672//
191209
extra_hosts:
192210
- minio:host-gateway
193211
networks:

processing_services/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ services:
1616
context: ./minimal
1717
command: ./celery_worker/start_celery.sh
1818
environment:
19-
- CELERY_BROKER_URL=amqp://user:password@rabbitmq:5672//
19+
- CELERY_BROKER_URL=amqp://rabbituser:rabbitpass@rabbitmq:5672//
2020
extra_hosts:
2121
- minio:host-gateway
2222
networks:
@@ -42,7 +42,7 @@ services:
4242
context: ./example
4343
command: ./celery_worker/start_celery.sh
4444
environment:
45-
- CELERY_BROKER_URL=amqp://user:password@rabbitmq:5672//
45+
- CELERY_BROKER_URL=amqp://rabbituser:rabbitpass@rabbitmq:5672//
4646
extra_hosts:
4747
- minio:host-gateway
4848
networks:

0 commit comments

Comments
 (0)