Skip to content

Commit e74d2c7

Browse files
committed
feat: remove job from redis before deleting the run
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 05478cf commit e74d2c7

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

‎vulnerabilities/models.py‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import xml.etree.ElementTree as ET
1515
from contextlib import suppress
1616
from functools import cached_property
17+
from inspect import cleandoc
1718
from itertools import groupby
1819
from operator import attrgetter
1920
from traceback import format_exc as traceback_format_exc
@@ -2073,7 +2074,7 @@ def pipeline_class(self):
20732074

20742075
@property
20752076
def job(self):
2076-
with suppress(NoSuchJobError):
2077+
with suppress(redis.exceptions.ConnectionError, NoSuchJobError):
20772078
return Job.fetch(
20782079
str(self.run_id),
20792080
connection=django_rq.get_connection(),
@@ -2219,20 +2220,19 @@ def stop_run(self):
22192220
)
22202221
self.set_run_stopped()
22212222

2222-
def delete_run(self, delete_self=True):
2223+
def delete_run(self):
22232224
if job := self.job:
22242225
job.delete()
22252226

2226-
if delete_self:
2227-
self.delete()
2228-
22292227
def delete(self, *args, **kwargs):
22302228
"""
22312229
Before deletion of the run instance, try to stop the run execution.
22322230
"""
22332231
with suppress(redis.exceptions.ConnectionError, AttributeError):
22342232
self.stop_run()
22352233

2234+
self.delete_run()
2235+
22362236
return super().delete(*args, **kwargs)
22372237

22382238
def append_to_log(self, message, is_multiline=False):
@@ -2366,16 +2366,20 @@ def pipeline_class(self):
23662366
from vulnerabilities.importers import IMPORTERS_REGISTRY
23672367
from vulnerabilities.improvers import IMPROVERS_REGISTRY
23682368
from vulnerabilities.pipelines.exporters import EXPORTERS_REGISTRY
2369+
from vulnerabilities.pipelines.management import MANAGEMENT_REGISTRY
23692370

2370-
pipeline_registry = IMPORTERS_REGISTRY | IMPROVERS_REGISTRY | EXPORTERS_REGISTRY
2371+
pipeline_registry = (
2372+
IMPORTERS_REGISTRY | IMPROVERS_REGISTRY | EXPORTERS_REGISTRY | MANAGEMENT_REGISTRY
2373+
)
23712374

23722375
return pipeline_registry[self.pipeline_id]
23732376

23742377
@property
23752378
def description(self):
23762379
"""Return the pipeline class."""
2380+
23772381
if self.pipeline_class:
2378-
return self.pipeline_class.__doc__
2382+
return cleandoc(self.pipeline_class.__doc__ or "")
23792383

23802384
@property
23812385
def all_runs(self):

0 commit comments

Comments
 (0)