Skip to content

Commit dd9668c

Browse files
committed
Allow toggling live logging for pipelines
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent a5383b5 commit dd9668c

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 4.2.20 on 2025-05-24 16:10
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("vulnerabilities", "0093_pipelineschedule_execution_timeout"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="pipelineschedule",
15+
name="live_logging",
16+
field=models.BooleanField(
17+
db_index=True,
18+
default=False,
19+
help_text="When enabled logs will be streamed live during pipeline execution. For legacy importers and improvers, logs are always made available only after execution completes.",
20+
),
21+
),
22+
]

vulnerabilities/models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,6 +2129,16 @@ class PipelineSchedule(models.Model):
21292129
),
21302130
)
21312131

2132+
live_logging = models.BooleanField(
2133+
null=False,
2134+
db_index=True,
2135+
default=False,
2136+
help_text=(
2137+
"When enabled logs will be streamed live during pipeline execution. "
2138+
"For legacy importers and improvers, logs are always made available only after execution completes."
2139+
),
2140+
)
2141+
21322142
run_interval = models.PositiveSmallIntegerField(
21332143
validators=[
21342144
MinValueValidator(1, message="Interval must be at least 1 day."),

vulnerabilities/pipelines/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,15 @@ def __init__(
5858
self.current_step = ""
5959

6060
def append_to_log(self, message):
61-
if self.run:
61+
if self.run and self.run.pipeline.live_logging:
6262
self.run.append_to_log(message)
6363
self.execution_log.append(message)
6464

65+
def update_final_run_log(self):
66+
if self.run and not self.run.pipeline.live_logging:
67+
final_log = "\n".join(self.execution_log)
68+
self.run.append_to_log(final_log, is_multiline=True)
69+
6570
def set_current_step(self, message):
6671
self.current_step = message
6772

@@ -106,6 +111,7 @@ def execute(self):
106111
self.on_failure()
107112
on_failure_run_time = timer() - on_failure_start_time
108113
self.log(f"Completed [on_failure] tasks in {humanize_time(on_failure_run_time)}")
114+
self.update_final_run_log()
109115

110116
return 1, self.output_from_exception(exception)
111117

@@ -115,6 +121,7 @@ def execute(self):
115121
self.set_current_step("") # Reset the `current_step` field on completion
116122
pipeline_run_time = timer() - pipeline_start_time
117123
self.log(f"Pipeline completed in {humanize_time(pipeline_run_time)}")
124+
self.update_final_run_log()
118125

119126
return 0, ""
120127

vulnerabilities/templates/pipeline_run_details.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ <h1 class="title">{{ pipeline_name }} Run Log</h1>
112112
</div>
113113
</div>
114114

115+
{% if not run.run_end_date and not run.pipeline.live_logging %}
116+
<div class="notification is-info is-light has-text-centered">
117+
<p class="is-size-6 has-text-grey-dark">
118+
<i class="fa fa-exclamation-triangle mr-1"></i>
119+
Live logging is disabled for this pipeline.
120+
Logs will be available after the pipeline has finished running.
121+
</p>
122+
</div>
123+
{% endif %}
124+
115125
{% if run.run_output|strip %}
116126
<div class="box">
117127
<h2 class="subtitle mb-2">Run Error</h2>

0 commit comments

Comments
 (0)