Files
kami_apple_exchage/backend/docker-entrypoint.sh
danial 8ad2a5366a refactor(backend): 将Celery替换为Arq进行协程任务处理
本次提交将后端的任务队列系统从Celery迁移到了Arq,以支持基于协程的任务处理。主要改动包括:
- 更新文档和配置文件,反映架构变化。
- 修改健康检查和服务初始化逻辑,以适应Arq的使用。
- 移除与Celery相关的代码,并添加Arq任务定义和调度器。
- 更新Dockerfile和相关脚本,确保Arq worker能够正确运行。
- 调整API和业务服务中的任务处理逻辑,移除对Celery的依赖。

这些改动旨在提高系统的异步处理能力和整体性能。
2025-09-18 16:02:05 +08:00

68 lines
2.3 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -e
# 设置时区
ln -sf /usr/share/zoneinfo/$TZ /etc/localtime
echo $TZ > /etc/timezone
# 检查是否为worker服务
if [ "$SERVICE_TYPE" = "worker" ]; then
echo "Checking Playwright browser installation..."
# 运行时检查和安装Playwright浏览器
if ! python -c "from playwright.sync_api import sync_playwright; import sys;
try:
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
browser.close()
print('Playwright is working')
sys.exit(0)
except Exception as e:
print(f'Playwright check failed: {e}')
sys.exit(1)"; then
echo "Installing Playwright browsers..."
python -m playwright install chromium --with-deps
# 确保浏览器文件有执行权限
if [ -d "/app/playwright-browsers" ]; then
find /app/playwright-browsers -type f -name "chrome*" -exec chmod +x {} \; 2>/dev/null || true
fi
else
echo "Playwright is already properly installed"
fi
# 额外确保权限正确
if [ -d "/app/playwright-browsers" ]; then
find /app/playwright-browsers -type f -exec chmod +x {} \; 2>/dev/null || true
fi
fi
# 根据服务类型启动相应的服务
if [ "$SERVICE_TYPE" = "api" ]; then
exec gunicorn app.main:app \
--workers ${WORKERS:-4} \
--worker-class uvicorn.workers.UvicornWorker \
--bind 0.0.0.0:8000 \
--timeout ${GUNICORN_TIMEOUT:-120} \
--keep-alive 5 \
--max-requests 1000 \
--max-requests-jitter 100 \
--worker-tmp-dir /dev/shm \
--log-level info
elif [ "$SERVICE_TYPE" = "worker" ]; then
# 使用Arq worker替代Celery支持协程池
# 确保Python能够找到app模块
export PYTHONPATH="/app:$PYTHONPATH"
exec python scripts/start_arq_worker.py
elif [ "$SERVICE_TYPE" = "beat" ]; then
echo "Arq worker已经内置定时任务功能无需单独的beat服务"
echo "请使用SERVICE_TYPE=worker启动Arq worker"
exit 1
elif [ "$SERVICE_TYPE" = "flower" ]; then
echo "Arq使用内置的监控功能无需单独的flower服务"
echo "Arq worker健康检查可通过HTTP端点进行监控"
exit 1
else
echo "SERVICE_TYPE must be 'api', 'worker', 'beat', or 'flower'"
exit 1
fi