Skip to content

Commit

Permalink
Add a current_step field on the Run model #300
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Druez <tdruez@nexb.com>
  • Loading branch information
tdruez committed Jul 25, 2022
1 parent 0698b8b commit 1329f8e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
18 changes: 18 additions & 0 deletions scanpipe/migrations/0019_run_current_step.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
1 change: 1 addition & 0 deletions scanpipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 9 additions & 3 deletions scanpipe/pipelines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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:
Expand Down

0 comments on commit 1329f8e

Please # to comment.