Skip to content

Commit 9bdeba6

Browse files
committed
Ensure run fields are reset before job requeue
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent a34f485 commit 9bdeba6

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

vulnerabilities/models.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,7 @@ def run_failed(self):
19561956
end_date = job.ended_at.replace(tzinfo=datetime.timezone.utc)
19571957
self.set_run_ended(
19581958
exitcode=1,
1959-
output=f"Killed from outside, exc_info={job.latest_result().exc_string}",
1959+
output=f"Killed from outside, exc_info={job.exc_info}",
19601960
end_date=end_date,
19611961
)
19621962
return True
@@ -2011,7 +2011,8 @@ def set_vulnerablecode_version_and_commit(self):
20112011
self.save(update_fields=["vulnerablecode_version", "vulnerablecode_commit"])
20122012

20132013
def set_run_started(self):
2014-
"""Set the `run_start_date` fields before starting the run execution."""
2014+
"""Reset the run and set `run_start_date` fields before starting run execution."""
2015+
self.reset_run()
20152016
self.run_start_date = timezone.now()
20162017
self.save(update_fields=["run_start_date"])
20172018

@@ -2030,6 +2031,17 @@ def set_run_stopped(self):
20302031
"""Set the execution as `stopped` using a special 99 exitcode value."""
20312032
self.set_run_ended(exitcode=99)
20322033

2034+
def reset_run(self):
2035+
"""Reset the run-related fields."""
2036+
self.run_start_date = None
2037+
self.run_end_date = None
2038+
self.run_exitcode = None
2039+
self.vulnerablecode_version = None
2040+
self.vulnerablecode_commit = None
2041+
self.run_output = ""
2042+
self.log = ""
2043+
self.save()
2044+
20332045
def stop_run(self):
20342046
if self.run_succeeded:
20352047
return
@@ -2049,7 +2061,7 @@ def stop_run(self):
20492061
end_date = job.ended_at.replace(tzinfo=datetime.timezone.utc)
20502062
self.set_run_ended(
20512063
exitcode=1,
2052-
output=f"Killed from outside, exc_info={job.latest_result().exc_string}",
2064+
output=f"Killed from outside, exc_info={job.exc_info}",
20532065
end_date=end_date,
20542066
)
20552067
return

vulnerabilities/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def execute_pipeline(pipeline_id, run_id):
3232
run = models.PipelineRun.objects.get(
3333
run_id=run_id,
3434
)
35-
run.set_vulnerablecode_version_and_commit()
3635
run.set_run_started()
36+
run.set_vulnerablecode_version_and_commit()
3737

3838
output = ""
3939
exitcode = 0

0 commit comments

Comments
 (0)