From 5dd42f653304039e4907f08280e37d2f548c58f2 Mon Sep 17 00:00:00 2001 From: Marco Donadoni Date: Thu, 21 Sep 2023 17:59:50 +0200 Subject: [PATCH] cli: fix graceful shutdown of `start-scheduler` Handle SIGTERM in `start-scheduler` to gracefully stop consuming the workflow submission queue. Closes reanahub/reana-job-controller#347 --- CHANGES.rst | 1 + reana_server/cli.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index b3c8a0b5..f9d30c3c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -15,6 +15,7 @@ Version 0.9.1 (UNRELEASED) - Fixes GitLab integration to automatically redirect the user to the correct URL when the access request is accepted. - Fixes authentication flow to correctly deny access to past revoked tokens in case the same user has also other new active tokens. - Fixes the email templates to show the correct ``kubectl`` commands when REANA is deployed inside a non-default namespace or with a custom component name prefix. +- Fixes graceful shutdown for ``start-scheduler`` command when being terminated. - Adds logic to support SSO with third-party Keycloak authentication services to ``config.py``. Version 0.9.0 (2023-01-19) diff --git a/reana_server/cli.py b/reana_server/cli.py index 18f7e376..24fd3d54 100644 --- a/reana_server/cli.py +++ b/reana_server/cli.py @@ -9,6 +9,7 @@ """REANA Server command line tool.""" import logging +import signal import click from reana_commons.config import REANA_LOG_FORMAT, REANA_LOG_LEVEL @@ -21,5 +22,12 @@ def start_scheduler(): """Start a workflow execution scheduler process.""" logging.basicConfig(level=REANA_LOG_LEVEL, format=REANA_LOG_FORMAT, force=True) scheduler = WorkflowExecutionScheduler() + + def stop_scheduler(signum, frame): + logging.info("Stopping scheduler...") + scheduler.should_stop = True + + signal.signal(signal.SIGTERM, stop_scheduler) + logging.info("Starting scheduler...") scheduler.run()