Skip to content

Commit eed49d3

Browse files
committed
Register the snapshot pipeline
Signed-off-by: Sampurna Pyne <sampurnapyne1710@gmail.com>
1 parent b32789d commit eed49d3

2 files changed

Lines changed: 16 additions & 19 deletions

File tree

‎insights/insights_snapshot_pipeline.py‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from aboutcode.pipeline import LoopProgress
1010
from django.db import transaction
1111

12-
from insights.graphs import GRAPHS
12+
from insights.charts import CHARTS
1313
from insights.models import DailySnapshot
1414
from insights.models import ImporterInsight
1515
from insights.models import PackageCWEInsight
@@ -27,12 +27,12 @@ class InsightsSnapshotPipeline(VulnerableCodePipeline):
2727
@classmethod
2828
def steps(cls):
2929
return (
30-
cls.compute_graph_analytics,
30+
cls.compute_chart_analytics,
3131
cls.save_snapshot,
3232
)
3333

34-
def compute_graph_analytics(self):
35-
"""Run graph collect_fns to compute analytics."""
34+
def compute_chart_analytics(self):
35+
"""Run chart collect_fns to compute analytics."""
3636

3737
# List all package types
3838
self.packages = list(PackageV2.objects.order_by().values_list("type", flat=True).distinct())
@@ -42,49 +42,44 @@ def compute_graph_analytics(self):
4242
self.package_cwes = []
4343
self.importer_insights = []
4444
self.severity_insight = None
45-
46-
active_graphs = {
47-
graph_id: graph_def for graph_id, graph_def in GRAPHS.items() if graph_def.collect_fn
48-
}
45+
active_charts = [chart_def for chart_def in CHARTS if chart_def.collect_fn]
4946

5047
# Count steps for progress bar
5148
total_steps = sum(
52-
len(self.packages) if graph_def.is_per_package else 1
53-
for graph_def in active_graphs.values()
49+
len(self.packages) if chart_def.is_per_package else 1 for chart_def in active_charts
5450
)
5551

5652
progress = LoopProgress(total_iterations=total_steps, logger=self.log, progress_step=1)
5753
progress_iter = iter(progress.iter(range(total_steps)))
5854

59-
for graph_id, graph_def in active_graphs.items():
60-
self.log(f"Running collect_fn for {graph_id}")
55+
for chart_def in active_charts:
56+
self.log(f"Running collect_fn for {chart_def.id}")
6157

62-
if graph_def.is_per_package:
58+
if chart_def.is_per_package:
6359
for pkg in self.packages:
6460
next(progress_iter, None)
65-
graph_def.collect_fn(self, pkg)
61+
chart_def.collect_fn(self, pkg)
6662
else:
6763
next(progress_iter, None)
68-
graph_def.collect_fn(self)
64+
chart_def.collect_fn(self)
6965

7066
@transaction.atomic
7167
def save_snapshot(self):
7268
self.log("Saving snapshot")
7369
snapshot = DailySnapshot.objects.create()
7470

7571
for insight in self.package_insights.values():
76-
insight.snapshot = snapshot
72+
insight.snapshot_id = snapshot.id
7773

7874
for insight in self.importer_insights:
79-
insight.snapshot = snapshot
75+
insight.snapshot_id = snapshot.id
8076

8177
if self.severity_insight:
82-
self.severity_insight.snapshot = snapshot
78+
self.severity_insight.snapshot_id = snapshot.id
8379
self.severity_insight.save()
8480

8581
PackageInsight.objects.bulk_create(self.package_insights.values(), batch_size=5000)
8682
PackageNameInsight.objects.bulk_create(self.package_names, batch_size=5000)
8783
PackageCWEInsight.objects.bulk_create(self.package_cwes, batch_size=5000)
8884
ImporterInsight.objects.bulk_create(self.importer_insights, batch_size=5000)
89-
9085
self.log("Snapshot saved successfully.")

‎vulnerabilities/improvers/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# See https://aboutcode.org for more information about nexB OSS projects.
88
#
99

10+
from insights.insights_snapshot_pipeline import InsightsSnapshotPipeline
1011
from vulnerabilities.pipelines.v2_improvers import archive_urls
1112
from vulnerabilities.pipelines.v2_improvers import collect_ssvc_trees
1213
from vulnerabilities.pipelines.v2_improvers import compute_advisory_todo as compute_advisory_todo_v2
@@ -43,5 +44,6 @@
4344
enhance_with_github_poc.GithubPocsImproverPipeline,
4445
mark_unfurl_version_range.MarkUnfurlVersionRangePipeline,
4546
group_advisories_for_packages_v2.GroupAdvisoriesForPackages,
47+
InsightsSnapshotPipeline,
4648
]
4749
)

0 commit comments

Comments
 (0)