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

global: fix graceful shutdown #526

Merged
merged 1 commit into from
Sep 26, 2023
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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Version 0.9.1 (UNRELEASED)
- Changes uWSGI configuration to increase buffer size, add vacuum option, etc.
- Fixes job status inconsistency by correctly setting running jobs' status to ``stopped`` when a workflow is stopped.
- Fixes uWSGI memory consumption on systems with very high allowed number of open files.
- Fixes uWSGI and ``consume-job-queue`` command to gracefully stop when being terminated.

Version 0.9.0 (2023-01-19)
--------------------------
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ ENV FLASK_APP=reana_workflow_controller/app.py \
EXPOSE 5000

# Run server
# exec is used to make sure signals are propagated to uwsgi,
# while also allowing shell expansion
# hadolint ignore=DL3025
CMD uwsgi \
CMD exec uwsgi \
--buffer-size ${UWSGI_BUFFER_SIZE} \
--die-on-term \
--hook-master-start "unix_signal:2 gracefully_kill_them_all" \
--hook-master-start "unix_signal:15 gracefully_kill_them_all" \
--enable-threads \
--http-socket 0.0.0.0:5000 \
--master \
Expand Down
9 changes: 9 additions & 0 deletions reana_workflow_controller/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""REANA Workflow Controller command line interface."""

import logging
import signal

Check warning on line 12 in reana_workflow_controller/cli.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/cli.py#L12

Added line #L12 was not covered by tests

import click
from reana_commons.config import REANA_LOG_FORMAT, REANA_LOG_LEVEL
Expand All @@ -21,4 +22,12 @@
"""Consumes job queue and updates job status."""
logging.basicConfig(level=REANA_LOG_LEVEL, format=REANA_LOG_FORMAT)
consumer = JobStatusConsumer()

def stop_consumer(signum, frame):
logging.info("Stopping job status consumer...")
consumer.should_stop = True

Check warning on line 28 in reana_workflow_controller/cli.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/cli.py#L26-L28

Added lines #L26 - L28 were not covered by tests

signal.signal(signal.SIGTERM, stop_consumer)

Check warning on line 30 in reana_workflow_controller/cli.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/cli.py#L30

Added line #L30 was not covered by tests

logging.info("Starting job status consumer...")

Check warning on line 32 in reana_workflow_controller/cli.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/cli.py#L32

Added line #L32 was not covered by tests
consumer.run()