| 29 | |
| 30 | |
| 31 | def execute_pipeline(pipeline_id, run_id): |
| 32 | from vulnerabilities.pipelines import VulnerableCodePipeline |
| 33 | |
| 34 | logger.info(f"Enter `execute_pipeline` {pipeline_id}") |
| 35 | |
| 36 | run = models.PipelineRun.objects.get( |
| 37 | run_id=run_id, |
| 38 | ) |
| 39 | run.set_run_started() |
| 40 | run.set_vulnerablecode_version_and_commit() |
| 41 | |
| 42 | output = "" |
| 43 | exitcode = 0 |
| 44 | run_class = run.pipeline_class |
| 45 | if issubclass(run_class, VulnerableCodePipeline): |
| 46 | pipeline_instance = run_class(run_instance=run) |
| 47 | exitcode, output = pipeline_instance.execute() |
| 48 | elif issubclass(run_class, Importer) or issubclass(run_class, Improver): |
| 49 | exitcode, output = legacy_runner(run_class=run_class, run=run) |
| 50 | else: |
| 51 | output = f"{pipeline_id} is not a valid importer/improver." |
| 52 | exitcode = 1 |
| 53 | |
| 54 | run.set_run_ended(exitcode=exitcode, output=output) |
| 55 | |
| 56 | # Onetime pipeline are inactive after first execution. |
| 57 | pipeline = run.pipeline |
| 58 | if pipeline.is_run_once: |
| 59 | pipeline.is_active = False |
| 60 | pipeline.save() |
| 61 | |
| 62 | logger.info("Update Run instance with exitcode, output, and end_date") |
| 63 | |
| 64 | |
| 65 | def legacy_runner(run_class, run): |