Skip to content

Commit f83ad8c

Browse files
t0mdavid-mclaudeCopilot
authored
Redis queue system for online mode (#305)
* Add Redis queue implementation plan for online mode This document outlines the architecture and implementation steps for introducing a Redis-based job queueing system to online deployments: - Uses RQ (Redis Queue) for task management - Docker Compose additions for Redis, worker, and dashboard services - New QueueManager class for queue interactions - Worker tasks module for background execution - Health monitoring utilities - Backward compatible with local mode (multiprocessing fallback) * Simplify to single-container architecture for Redis queue Update implementation plan to run Redis server and RQ worker within the same Docker container as the Streamlit app: - Redis server runs as background process via entrypoint script - RQ worker runs in same container with identical environment - No docker-compose orchestration complexity - All communication via localhost - Optional supervisord config for robust process management - Simplified deployment and debugging * Expand implementation plan with offline mode, worker config, and UX details - Add "Design Principles" section explaining plug & play architecture - Document offline mode (Windows installer) compatibility - zero changes needed - Add comprehensive "Configuring Worker Count" section with multiple methods - Add "User Experience: Queue Status Display" section showing what users see - Add "Sidebar Metrics" section for queue monitoring alongside CPU/RAM - Include code examples for all UI components * Implement Redis queue system for online mode workflows New files: - src/workflow/QueueManager.py: Redis queue interaction layer - src/workflow/tasks.py: Worker task definitions for RQ - src/workflow/health.py: Queue health check utilities Modified files: - Dockerfile: Install Redis server, add entrypoint for Redis/RQ workers - requirements.txt: Add redis and rq packages - settings.json: Add queue_settings configuration - src/workflow/WorkflowManager.py: Add queue support with local fallback - src/workflow/StreamlitUI.py: Add queue status display in execution section - src/common/common.py: Add sidebar queue metrics for online mode Features: - Automatic queue mode in online deployment, local mode unchanged - Queue position and progress display when workflows are queued - Sidebar metrics showing worker utilization and queue depth - Configurable worker count via RQ_WORKER_COUNT env variable - Graceful fallback to multiprocessing if Redis unavailable * Update settings.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix redis queue handling * minor fixes * minor fixes --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 2ee6466 commit f83ad8c

File tree

11 files changed

+2563
-38
lines changed

11 files changed

+2563
-38
lines changed

Dockerfile

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ RUN rm -rf openms-build
118118

119119
# Prepare and run streamlit app.
120120
FROM compile-openms AS run-app
121+
122+
# Install Redis server for job queue
123+
RUN apt-get update && apt-get install -y --no-install-recommends redis-server \
124+
&& rm -rf /var/lib/apt/lists/*
125+
126+
# Create Redis data directory
127+
RUN mkdir -p /var/lib/redis && chown redis:redis /var/lib/redis
128+
121129
# Create workdir and copy over all streamlit related files/folders.
122130

123131
# note: specifying folder with slash as suffix and repeating the folder name seems important to preserve directory structure
@@ -141,11 +149,40 @@ COPY clean-up-workspaces.py /app/clean-up-workspaces.py
141149
# add cron job to the crontab
142150
RUN echo "0 3 * * * /root/miniforge3/envs/streamlit-env/bin/python /app/clean-up-workspaces.py >> /app/clean-up-workspaces.log 2>&1" | crontab -
143151

144-
# create entrypoint script to start cron service and launch streamlit app
145-
RUN echo "#!/bin/bash" > /app/entrypoint.sh && \
146-
echo "source /root/miniforge3/bin/activate streamlit-env" >> /app/entrypoint.sh && \
147-
echo "service cron start" >> /app/entrypoint.sh && \
148-
echo "streamlit run app.py" >> /app/entrypoint.sh
152+
# Set default worker count (can be overridden via environment variable)
153+
ENV RQ_WORKER_COUNT=1
154+
ENV REDIS_URL=redis://localhost:6379/0
155+
156+
# create entrypoint script to start cron, Redis, RQ workers, and Streamlit
157+
RUN echo -e '#!/bin/bash\n\
158+
set -e\n\
159+
source /root/miniforge3/bin/activate streamlit-env\n\
160+
\n\
161+
# Start cron for workspace cleanup\n\
162+
service cron start\n\
163+
\n\
164+
# Start Redis server in background\n\
165+
echo "Starting Redis server..."\n\
166+
redis-server --daemonize yes --dir /var/lib/redis --appendonly no\n\
167+
\n\
168+
# Wait for Redis to be ready\n\
169+
until redis-cli ping > /dev/null 2>&1; do\n\
170+
echo "Waiting for Redis..."\n\
171+
sleep 1\n\
172+
done\n\
173+
echo "Redis is ready"\n\
174+
\n\
175+
# Start RQ worker(s) in background\n\
176+
WORKER_COUNT=${RQ_WORKER_COUNT:-1}\n\
177+
echo "Starting $WORKER_COUNT RQ worker(s)..."\n\
178+
for i in $(seq 1 $WORKER_COUNT); do\n\
179+
rq worker openms-workflows --url $REDIS_URL --name worker-$i &\n\
180+
done\n\
181+
\n\
182+
# Start Streamlit (foreground - main process)\n\
183+
echo "Starting Streamlit app..."\n\
184+
exec streamlit run app.py\n\
185+
' > /app/entrypoint.sh
149186
# make the script executable
150187
RUN chmod +x /app/entrypoint.sh
151188

0 commit comments

Comments
 (0)