Skip to content

Commit 086c46c

Browse files
author
kkthxbye
committed
Save old JobResults
1 parent e09ab79 commit 086c46c

File tree

6 files changed

+6
-40
lines changed

6 files changed

+6
-40
lines changed

netbox/extras/api/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def list(self, request):
197197
for r in JobResult.objects.filter(
198198
obj_type=report_content_type,
199199
status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
200-
).defer('data')
200+
).order_by('name', '-created').distinct('name').defer('data')
201201
}
202202

203203
# Iterate through all available Reports.
@@ -288,7 +288,7 @@ def list(self, request):
288288
for r in JobResult.objects.filter(
289289
obj_type=script_content_type,
290290
status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
291-
).defer('data').order_by('created')
291+
).order_by('name', '-created').distinct('name').defer('data')
292292
}
293293

294294
flat_list = []

netbox/extras/management/commands/runscript.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,6 @@ def _run_script():
113113

114114
script_content_type = ContentType.objects.get(app_label='extras', model='script')
115115

116-
# Delete any previous terminal state results
117-
JobResult.objects.filter(
118-
obj_type=script_content_type,
119-
name=script.full_name,
120-
status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
121-
).delete()
122-
123116
# Create the job result
124117
job_result = JobResult.objects.create(
125118
name=script.full_name,

netbox/extras/reports.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,6 @@ def run_report(job_result, *args, **kwargs):
8484
job_result.save()
8585
logging.error(f"Error during execution of report {job_result.name}")
8686

87-
# Delete any previous terminal state results
88-
JobResult.objects.filter(
89-
obj_type=job_result.obj_type,
90-
name=job_result.name,
91-
status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
92-
).exclude(
93-
pk=job_result.pk
94-
).delete()
95-
9687

9788
class Report(object):
9889
"""

netbox/extras/scripts.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -478,23 +478,14 @@ def _run_script():
478478
else:
479479
_run_script()
480480

481-
# Delete any previous terminal state results
482-
JobResult.objects.filter(
483-
obj_type=job_result.obj_type,
484-
name=job_result.name,
485-
status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
486-
).exclude(
487-
pk=job_result.pk
488-
).delete()
489-
490481

491482
def get_scripts(use_names=False):
492483
"""
493484
Return a dict of dicts mapping all scripts to their modules. Set use_names to True to use each module's human-
494485
defined name in place of the actual module name.
495486
"""
496487
scripts = OrderedDict()
497-
# Iterate through all modules within the reports path. These are the user-created files in which reports are
488+
# Iterate through all modules within the scripts path. These are the user-created files in which reports are
498489
# defined.
499490
for importer, module_name, _ in pkgutil.iter_modules([settings.SCRIPTS_ROOT]):
500491
# Remove cached module to ensure consistency with filesystem

netbox/extras/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ def get(self, request):
617617
for r in JobResult.objects.filter(
618618
obj_type=report_content_type,
619619
status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
620-
).defer('data')
620+
).order_by('name', '-created').distinct('name').defer('data')
621621
}
622622

623623
ret = []
@@ -748,7 +748,7 @@ def get(self, request):
748748
for r in JobResult.objects.filter(
749749
obj_type=script_content_type,
750750
status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
751-
).defer('data')
751+
).order_by('name', '-created').distinct('name').defer('data')
752752
}
753753

754754
for _scripts in scripts.values():

netbox/netbox/views/__init__.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
from dcim.models import (
2020
Cable, ConsolePort, Device, DeviceType, Interface, PowerPanel, PowerFeed, PowerPort, Rack, Site,
2121
)
22-
from extras.choices import JobResultStatusChoices
23-
from extras.models import ObjectChange, JobResult
22+
from extras.models import ObjectChange
2423
from extras.tables import ObjectChangeTable
2524
from ipam.models import Aggregate, IPAddress, IPRange, Prefix, VLAN, VRF
2625
from netbox.constants import SEARCH_MAX_RESULTS, SEARCH_TYPES
@@ -48,13 +47,6 @@ def get(self, request):
4847
pk__lt=F('_path__destination_id')
4948
)
5049

51-
# Report Results
52-
report_content_type = ContentType.objects.get(app_label='extras', model='report')
53-
report_results = JobResult.objects.filter(
54-
obj_type=report_content_type,
55-
status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES
56-
).defer('data')[:10]
57-
5850
def build_stats():
5951
org = (
6052
("dcim.view_site", "Sites", Site.objects.restrict(request.user, 'view').count),
@@ -150,7 +142,6 @@ def build_stats():
150142
return render(request, self.template_name, {
151143
'search_form': SearchForm(),
152144
'stats': build_stats(),
153-
'report_results': report_results,
154145
'changelog_table': changelog_table,
155146
'new_release': new_release,
156147
})

0 commit comments

Comments
 (0)