From 1329f8e7859b225769765566b81de7c782fda688 Mon Sep 17 00:00:00 2001 From: Thomas Druez Date: Mon, 25 Jul 2022 11:29:58 +0400 Subject: [PATCH] Add a current_step field on the Run model #300 Signed-off-by: Thomas Druez --- scanpipe/migrations/0019_run_current_step.py | 18 ++++++++++++++++++ scanpipe/models.py | 1 + scanpipe/pipelines/__init__.py | 12 +++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 scanpipe/migrations/0019_run_current_step.py diff --git a/scanpipe/migrations/0019_run_current_step.py b/scanpipe/migrations/0019_run_current_step.py new file mode 100644 index 000000000..d3eb87f56 --- /dev/null +++ b/scanpipe/migrations/0019_run_current_step.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.6 on 2022-07-22 07:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('scanpipe', '0018_codebaseresource_tag'), + ] + + operations = [ + migrations.AddField( + model_name='run', + name='current_step', + field=models.CharField(blank=True, max_length=256), + ), + ] diff --git a/scanpipe/models.py b/scanpipe/models.py index 06100f3a1..8140137fe 100644 --- a/scanpipe/models.py +++ b/scanpipe/models.py @@ -1031,6 +1031,7 @@ class Run(UUIDPKModel, ProjectRelatedModel, AbstractTaskFieldsModel): created_date = models.DateTimeField(auto_now_add=True, db_index=True) scancodeio_version = models.CharField(max_length=30, blank=True) description = models.TextField(blank=True) + current_step = models.CharField(max_length=256, blank=True) log = models.TextField(blank=True, editable=False) objects = RunQuerySet.as_manager() diff --git a/scanpipe/pipelines/__init__.py b/scanpipe/pipelines/__init__.py index a210dfa15..ba61b56ee 100644 --- a/scanpipe/pipelines/__init__.py +++ b/scanpipe/pipelines/__init__.py @@ -87,7 +87,7 @@ def get_graph(cls): @classmethod def get_info(cls): """ - Returns a dictctionary of combined data about the current pipeline. + Returns a dictionary of combined data about the current pipeline. """ return { "description": cls.get_doc(), @@ -106,9 +106,15 @@ def log(self, message): def execute(self): self.log(f"Pipeline [{self.pipeline_name}] starting") + steps = self.get_steps() + steps_count = len(steps) - for step in self.get_steps(): - self.log(f"Step [{step.__name__}] starting") + for current_index, step in enumerate(steps, start=1): + step_name = step.__name__ + + # The `current_step` value is saved in the DB during the `self.log` call. + self.run.current_step = f"[{current_index}/{steps_count}] {step_name}" + self.log(f"Step [{step_name}] starting") start_time = timeit.default_timer() try: