From 2077e935232566e9fa045f19e85733588046d363 Mon Sep 17 00:00:00 2001 From: Khushboo Date: Wed, 26 Jan 2022 13:48:21 +0530 Subject: [PATCH 1/2] Link shutdown routine to main thread --- st2actions/st2actions/cmd/actionrunner.py | 8 +++----- st2actions/st2actions/cmd/workflow_engine.py | 9 +++------ st2common/st2common/transport/consumers.py | 3 +++ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/st2actions/st2actions/cmd/actionrunner.py b/st2actions/st2actions/cmd/actionrunner.py index 76743ab707..05f48f6464 100644 --- a/st2actions/st2actions/cmd/actionrunner.py +++ b/st2actions/st2actions/cmd/actionrunner.py @@ -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. @@ -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() diff --git a/st2actions/st2actions/cmd/workflow_engine.py b/st2actions/st2actions/cmd/workflow_engine.py index dba392f100..e6eb65d5a8 100644 --- a/st2actions/st2actions/cmd/workflow_engine.py +++ b/st2actions/st2actions/cmd/workflow_engine.py @@ -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. @@ -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): @@ -79,7 +77,6 @@ def run_server(): except: LOG.exception("(PID=%s) Workflow engine unexpectedly stopped.", os.getpid()) return 1 - return 0 diff --git a/st2common/st2common/transport/consumers.py b/st2common/st2common/transport/consumers.py index 47752f035f..44d867962d 100644 --- a/st2common/st2common/transport/consumers.py +++ b/st2common/st2common/transport/consumers.py @@ -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 From c701a41794f85997b2c068df0111b5bb6a6a158b Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Tue, 1 Feb 2022 22:08:14 -0600 Subject: [PATCH 2/2] pre_job and required checks are fighting. Ignore for now. --- .github/workflows/ci.yaml | 10 +++++++--- .github/workflows/orquesta-integration-tests.yaml | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c1f592cf90..a5d41d3875 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/.github/workflows/orquesta-integration-tests.yaml b/.github/workflows/orquesta-integration-tests.yaml index 2975e6cf79..1e083e62a9 100644 --- a/.github/workflows/orquesta-integration-tests.yaml +++ b/.github/workflows/orquesta-integration-tests.yaml @@ -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: @@ -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: