feat(docreader): add health check

This commit is contained in:
wizardchen
2025-09-10 20:12:37 +08:00
committed by lyingbug
parent 8a2b38da6f
commit 6f6ca84dae
4 changed files with 22 additions and 1 deletions
+8
View File
@@ -68,6 +68,8 @@ services:
condition: service_healthy condition: service_healthy
minio: minio:
condition: service_started condition: service_started
docreader:
condition: service_healthy
networks: networks:
- WeKnora-network - WeKnora-network
restart: unless-stopped restart: unless-stopped
@@ -129,6 +131,12 @@ services:
- MINIO_BUCKET_NAME=${MINIO_BUCKET_NAME} - MINIO_BUCKET_NAME=${MINIO_BUCKET_NAME}
- MINIO_USE_SSL=${MINIO_USE_SSL} - MINIO_USE_SSL=${MINIO_USE_SSL}
- WEB_PROXY=${WEB_PROXY} - WEB_PROXY=${WEB_PROXY}
healthcheck:
test: ["CMD", "grpc_health_probe", "-addr=:50051"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
networks: networks:
- WeKnora-network - WeKnora-network
restart: unless-stopped restart: unless-stopped
+6
View File
@@ -114,8 +114,14 @@ RUN apt-get update && apt-get install -y \
libglu1-mesa \ libglu1-mesa \
libsm6 \ libsm6 \
libreoffice \ libreoffice \
curl \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# 安装 grpc_health_probe
RUN GRPC_HEALTH_PROBE_VERSION=v0.4.24 && \
wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
chmod +x /bin/grpc_health_probe
# 从构建阶段复制已安装的依赖和生成的代码 # 从构建阶段复制已安装的依赖和生成的代码
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin COPY --from=builder /usr/local/bin /usr/local/bin
+1
View File
@@ -1,5 +1,6 @@
grpcio grpcio
grpcio-tools grpcio-tools
grpcio-health-checking
protobuf protobuf
python-docx python-docx
PyPDF2 PyPDF2
+7 -1
View File
@@ -6,6 +6,8 @@ import traceback
import grpc import grpc
import uuid import uuid
import atexit import atexit
from grpc_health.v1 import health_pb2_grpc
from grpc_health.v1.health import HealthServicer
# Add parent directory to Python path # Add parent directory to Python path
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
@@ -348,9 +350,13 @@ def serve():
], ],
) )
# Register service # Register services
docreader_pb2_grpc.add_DocReaderServicer_to_server(DocReaderServicer(), server) docreader_pb2_grpc.add_DocReaderServicer_to_server(DocReaderServicer(), server)
# Register health check service
health_servicer = HealthServicer()
health_pb2_grpc.add_HealthServicer_to_server(health_servicer, server)
# Set listen address # Set listen address
server.add_insecure_port(f"[::]:{port}") server.add_insecure_port(f"[::]:{port}")