Skip to content

Link shutdown routine and sigterm handler to main thread #5555

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

Merged
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
10 changes: 7 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ on:
- cron: '0 0 * * *'

jobs:
# TODO: Fix the required checks!
# When the pre_job triggers and skips builds, it prevents merging the PR because
# the required checks are reported as skipped instead of passed.
# Special job which automatically cancels old runs for the same branch, prevents runs for the
# same file set which has already passed, etc.
pre_job:
Expand All @@ -40,7 +43,7 @@ jobs:
needs: pre_job
# NOTE: We always want to run job on master since we run some additional checks there (code
# coverage, etc)
if: ${{ needs.pre_job.outputs.should_skip != 'true' || github.ref == 'refs/heads/master' }}
# if: ${{ needs.pre_job.outputs.should_skip != 'true' || github.ref == 'refs/heads/master' }}
name: '${{ matrix.name }} - Python ${{ matrix.python-version-short }}'
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -135,7 +138,8 @@ jobs:
needs: pre_job
# NOTE: We always want to run job on master since we run some additional checks there (code
# coverage, etc)
if: ${{ needs.pre_job.outputs.should_skip != 'true' || github.ref == 'refs/heads/master' }}
# NB: disabled. See TODO above pre_job
# if: ${{ needs.pre_job.outputs.should_skip != 'true' || github.ref == 'refs/heads/master' }}
name: '${{ matrix.name }} - Python ${{ matrix.python-version-short }}'
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -304,7 +308,7 @@ jobs:
needs: pre_job
# NOTE: We always want to run job on master since we run some additional checks there (code
# coverage, etc)
if: ${{ needs.pre_job.outputs.should_skip != 'true' || github.ref == 'refs/heads/master' }}
# if: ${{ needs.pre_job.outputs.should_skip != 'true' || github.ref == 'refs/heads/master' }}
name: '${{ matrix.name }} - Python ${{ matrix.python-version-short }}'
runs-on: ubuntu-latest
strategy:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/orquesta-integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ on:
- cron: '0 0 * * *'

jobs:
# TODO: Fix the required checks!
# When the pre_job triggers and skips builds, it prevents merging the PR because
# the required checks are reported as skipped instead of passed.
# Special job which automatically cancels old runs for the same branch, prevents runs for the
# same file set which has already passed, etc.
pre_job:
Expand All @@ -43,7 +46,7 @@ jobs:
needs: pre_job
# NOTE: We always want to run job on master since we run some additional checks there (code
# coverage, etc)
if: ${{ needs.pre_job.outputs.should_skip != 'true' || github.ref == 'refs/heads/master' }}
# if: ${{ needs.pre_job.outputs.should_skip != 'true' || github.ref == 'refs/heads/master' }}
name: '${{ matrix.name }} - Python ${{ matrix.python-version-short }}'
runs-on: ubuntu-latest
strategy:
Expand Down
8 changes: 3 additions & 5 deletions st2actions/st2actions/cmd/actionrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
ACTIONRUNNER = "actionrunner"


def _setup_sigterm_handler():
def _setup_sigterm_handler(action_worker):
def sigterm_handler(signum=None, frame=None):
# This will cause SystemExit to be throw and allow for component cleanup.
sys.exit(0)
action_worker.kill()

# Register a SIGTERM signal handler which calls sys.exit which causes SystemExit to
# be thrown. We catch SystemExit and handle cleanup there.
Expand All @@ -60,14 +60,12 @@ def _setup():
capabilities=capabilities,
)

_setup_sigterm_handler()


def _run_worker():
LOG.info("(PID=%s) Worker started.", os.getpid())

action_worker = worker.get_worker()

_setup_sigterm_handler(action_worker)
try:
action_worker.start()
action_worker.wait()
Expand Down
9 changes: 3 additions & 6 deletions st2actions/st2actions/cmd/workflow_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
WORKFLOW_ENGINE = "workflow_engine"


def setup_sigterm_handler():
def setup_sigterm_handler(engine):
def sigterm_handler(signum=None, frame=None):
# This will cause SystemExit to be throw and allow for component cleanup.
sys.exit(0)
engine.kill()

# Register a SIGTERM signal handler which calls sys.exit which causes SystemExit to
# be thrown. We catch SystemExit and handle cleanup there.
Expand All @@ -62,14 +62,12 @@ def setup():
capabilities=capabilities,
)

setup_sigterm_handler()


def run_server():
LOG.info("(PID=%s) Workflow engine started.", os.getpid())

engine = workflows.get_engine()

setup_sigterm_handler(engine)
try:
engine.start(wait=True)
except (KeyboardInterrupt, SystemExit):
Expand All @@ -79,7 +77,6 @@ def run_server():
except:
LOG.exception("(PID=%s) Workflow engine unexpectedly stopped.", os.getpid())
return 1

return 0


Expand Down
3 changes: 3 additions & 0 deletions st2common/st2common/transport/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ def shutdown(self):
LOG.info("Shutting down %s...", self.__class__.__name__)
self._queue_consumer.shutdown()

def kill(self):
self._consumer_thread.kill(SystemExit())

@abc.abstractmethod
def process(self, message):
pass
Expand Down