Skip to content

Commit

Permalink
cli: fix graceful shutdown of start-scheduler
Browse files Browse the repository at this point in the history
Handle SIGTERM in `start-scheduler` to gracefully stop consuming
the workflow submission queue.

Closes reanahub/reana-job-controller#347
  • Loading branch information
mdonadoni committed Sep 21, 2023
1 parent a339846 commit 8acf5bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 ``start-scheduler`` command to gracefully stop when being terminated.
- Adds logic to support SSO with third-party Keycloak authentication services to ``config.py``.

Version 0.9.0 (2023-01-19)
Expand Down
8 changes: 8 additions & 0 deletions reana_server/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""REANA Server command line tool."""

import logging
import signal

Check warning on line 12 in reana_server/cli.py

View check run for this annotation

Codecov / codecov/patch

reana_server/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,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

Check warning on line 28 in reana_server/cli.py

View check run for this annotation

Codecov / codecov/patch

reana_server/cli.py#L26-L28

Added lines #L26 - L28 were not covered by tests

signal.signal(signal.SIGTERM, stop_scheduler)

Check warning on line 30 in reana_server/cli.py

View check run for this annotation

Codecov / codecov/patch

reana_server/cli.py#L30

Added line #L30 was not covered by tests

logging.info("Starting scheduler...")
scheduler.run()

0 comments on commit 8acf5bc

Please sign in to comment.