Skip to content

Commit

Permalink
Add support for stopping a pipeline run in the CLI execute command #176
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Druez <tdruez@nexb.com>
  • Loading branch information
tdruez committed Sep 27, 2021
1 parent d0f1a7d commit 12670ef
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions scanpipe/management/commands/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

from django.core.management import CommandError

import redis

from scanpipe.management.commands import ProjectCommand


Expand All @@ -38,8 +40,22 @@ def handle(self, *args, **options):
if not run:
raise CommandError(f"No pipelines to run on project {self.project}")

self.stdout.write(f"Pipeline {run.pipeline_name} run in progress...")
run.execute_task_async()
self.stdout.write(f"Start the {run.pipeline_name} pipeline execution...")

try:
run.execute_task_async()
except KeyboardInterrupt:
run.set_task_ended(exitcode=88)
self.stderr.write(self.style.ERROR("Pipeline execution stopped."))
sys.exit(1)
except redis.exceptions.RedisError as e:
msg = f"Error raised by the Redis client:\n{e}"
self.stderr.write(self.style.ERROR(msg))
sys.exit(1)
except Exception as e:
self.stderr.write(self.style.ERROR(e))
sys.exit(1)

run.refresh_from_db()

if run.task_succeeded:
Expand Down

0 comments on commit 12670ef

Please sign in to comment.