Skip to content

Commit

Permalink
Use project name as argument to run a pipeline #18
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 23, 2020
1 parent a27159e commit 6065f57
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

### v1.0.3 (unreleased)

- **ScanPipe** -- Use project name as argument to run a pipeline
Fix for https://github.com/nexB/scancode.io/issues/18

- **ScanPipe** -- Add support for "failed" task_output in Run.get_run_id method
Fix for https://github.com/nexB/scancode.io/issues/17

Expand Down
8 changes: 3 additions & 5 deletions scanpipe/pipelines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@ class Pipeline(FlowSpec):
Base class for all Pipelines.
"""

project_pk = Parameter(
"project", help="The project for running this Pipeline.", required=True
)
project_name = Parameter("project", help="Project name.", required=True)

@staticmethod
def get_project_instance(project_pk):
def get_project(name):
"""
Return the project instance from the database.
"""
from scanpipe.models import Project

return Project.objects.get(pk=project_pk)
return Project.objects.get(name=name)


class PipelineGraph(FlowGraph):
Expand Down
2 changes: 1 addition & 1 deletion scanpipe/pipelines/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def start(self):
"""
Load the Project instance.
"""
self.project = self.get_project_instance(self.project_pk)
self.project = self.get_project(self.project_name)
self.next(self.extract_images)

@step
Expand Down
2 changes: 1 addition & 1 deletion scanpipe/pipelines/root_filesystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def start(self):
"""
Load the Project instance.
"""
self.project = self.get_project_instance(self.project_pk)
self.project = self.get_project(self.project_name)
self.next(self.find_root_filesystems)

@step
Expand Down
2 changes: 1 addition & 1 deletion scanpipe/pipelines/scan_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def start(self):
"""
Load the Project instance.
"""
self.project = self.get_project_instance(self.project_pk)
self.project = self.get_project(self.project_name)
self.next(self.build_inventory_from_scan)

@step
Expand Down
6 changes: 3 additions & 3 deletions scanpipe/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def run_pipeline_task(self, run_pk):
run = get_run_instance(run_pk)
start_run(run, task_id)

info(f'Run pipeline: "{run.pipeline}" on project: "{run.project_id}"', run_pk)
cmd = f"{python} {run.pipeline} run --project {run.project_id}"
info(f'Run pipeline: "{run.pipeline}" on project: "{run.project.name}"', run_pk)
cmd = f"{python} {run.pipeline} run --project {run.project.name}"
exitcode, output = run_command(cmd)

info("Update Run instance with exitcode, output, and end_date", run_pk)
Expand All @@ -109,7 +109,7 @@ def resume_pipeline_task(self, run_pk):
start_run(run, task_id)
run_id = run.get_run_id()

info(f'Resume pipeline: "{run.pipeline}" on project: "{run.project_id}"', run_pk)
info(f'Resume pipeline: "{run.pipeline}" on project: "{run.project.name}"', run_pk)
cmd = f"{python} {run.pipeline} resume --origin-run-id {run_id}"
exitcode, output = run_command(cmd)

Expand Down
4 changes: 2 additions & 2 deletions scanpipe/tests/test_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class ScanPipeModelsTest(TestCase):
rootfs_pipeline_location = "scanpipe/pipelines/root_filesystems.py"
scan_pipeline_location = "scanpipe/pipelines/scan_inventory.py"

def test_scanpipe_pipeline_class_get_project_instance(self):
def test_scanpipe_pipeline_class_get_project(self):
project1 = Project.objects.create(name="Analysis")
project_instance = Pipeline.get_project_instance(project_pk=project1.pk)
project_instance = Pipeline.get_project(project1.name)
self.assertEqual(project1, project_instance)

def test_scanpipe_pipelines_is_pipeline_subclass(self):
Expand Down

0 comments on commit 6065f57

Please sign in to comment.