Skip to content

Commit c67cf66

Browse files
committed
Add setting to toggle live logging for pipelines
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 312674f commit c67cf66

4 files changed

Lines changed: 38 additions & 3 deletions

File tree

vulnerabilities/migrations/0092_pipelineschedule_pipelinerun.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 4.2.20 on 2025-05-21 19:32
1+
# Generated by Django 4.2.20 on 2025-05-26 11:38
22

33
import django.core.validators
44
from django.db import migrations, models
@@ -39,6 +39,14 @@ class Migration(migrations.Migration):
3939
null=True,
4040
),
4141
),
42+
(
43+
"live_logging",
44+
models.BooleanField(
45+
db_index=True,
46+
default=False,
47+
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.",
48+
),
49+
),
4250
(
4351
"run_interval",
4452
models.PositiveSmallIntegerField(

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: 11 additions & 1 deletion
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>
@@ -159,7 +169,7 @@ <h2 class="subtitle mb-2">Log Output</h2>
159169
{% endif %}
160170

161171
<a href="{% url 'runs-list' pipeline_id=run.pipeline.pipeline_id %}" class="button is-info mt-4">
162-
<i class="fa fa-arrow-left mr-2"></i>Back to AllRuns
172+
<i class="fa fa-arrow-left mr-2"></i>Back to All Runs
163173
</a>
164174
</div>
165175
</section>

0 commit comments

Comments
 (0)