mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
12510 legacy jobs
This commit is contained in:
parent
52689616e9
commit
e61b960cd7
@ -272,18 +272,17 @@ class BaseScript(object):
|
||||
def __init__(self):
|
||||
self._logs = {}
|
||||
self._failed = False
|
||||
self._current_method = 'totals'
|
||||
self._current_method = 'unassigned'
|
||||
self._output = ''
|
||||
|
||||
# Initiate the log
|
||||
self.logger = logging.getLogger(f"netbox.scripts.{self.__module__}.{self.__class__.__name__}")
|
||||
self.log = []
|
||||
|
||||
# Declare the placeholder for the current request
|
||||
self.request = None
|
||||
|
||||
# Compile test methods and initialize results skeleton
|
||||
self._logs['totals'] = {
|
||||
self._logs['unassigned'] = {
|
||||
'success': 0,
|
||||
'info': 0,
|
||||
'warning': 0,
|
||||
@ -454,8 +453,8 @@ class BaseScript(object):
|
||||
if log_level != LogLevelChoices.LOG_DEFAULT:
|
||||
self._logs[self._current_method][log_level] += 1
|
||||
|
||||
if self._current_method != 'totals':
|
||||
self._logs['totals'][log_level] += 1
|
||||
if self._current_method != 'unassigned':
|
||||
self._logs['unassigned'][log_level] += 1
|
||||
|
||||
if obj:
|
||||
self.logger.log(level, f"{log_level.capitalize()} | {obj}: {message}")
|
||||
@ -527,12 +526,12 @@ class BaseScript(object):
|
||||
test_method()
|
||||
except Exception as e:
|
||||
self.post_run()
|
||||
self._current_method = 'totals'
|
||||
self._current_method = 'unassigned'
|
||||
raise e
|
||||
|
||||
# Perform any post-run tasks
|
||||
self.post_run()
|
||||
self._current_method = 'totals'
|
||||
self._current_method = 'unassigned'
|
||||
|
||||
def run(self, data, commit):
|
||||
self.run_test_scripts()
|
||||
@ -650,12 +649,10 @@ def run_script(data, job, request=None, commit=True, **kwargs):
|
||||
|
||||
return fn(**kwargs)
|
||||
|
||||
def set_job_data(job, script):
|
||||
def set_job_data(script):
|
||||
logs = script._logs
|
||||
totals = logs.pop('totals')
|
||||
job.data = {
|
||||
'logs': logs,
|
||||
'totals': totals,
|
||||
'output': script._output,
|
||||
}
|
||||
return job
|
||||
@ -675,7 +672,7 @@ def run_script(data, job, request=None, commit=True, **kwargs):
|
||||
call_with_appropriate(script.log_info, kwargs={'message': "Database changes have been reverted automatically."})
|
||||
if request:
|
||||
clear_events.send(request)
|
||||
job = set_job_data(job, script)
|
||||
job = set_job_data(script)
|
||||
if script._failed:
|
||||
logger.warning(f"Script failed")
|
||||
job.terminate(status=JobStatusChoices.STATUS_FAILED)
|
||||
|
@ -1163,6 +1163,9 @@ class ScriptResultView(ContentTypePermissionRequiredMixin, View):
|
||||
module = job.object
|
||||
script = module.scripts[job.name]()
|
||||
|
||||
legacy_script = False
|
||||
legacy_report = False
|
||||
if job.data:
|
||||
if 'logs' in job.data:
|
||||
legacy_script = False
|
||||
legacy_report = False
|
||||
|
@ -89,6 +89,7 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% if last_job.data.logs %}
|
||||
{% for method, stats in last_job.data.logs.items %}
|
||||
<tr>
|
||||
<td colspan="4" class="method">
|
||||
@ -102,6 +103,22 @@
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% elif not last_job.data.log %}
|
||||
{# legacy #}
|
||||
{% for method, stats in last_job.data.items %}
|
||||
<tr>
|
||||
<td colspan="4" class="method">
|
||||
<span class="ps-3">{{ method }}</span>
|
||||
</td>
|
||||
<td class="text-end text-nowrap report-stats">
|
||||
<span class="badge bg-success">{{ stats.success }}</span>
|
||||
<span class="badge bg-info">{{ stats.info }}</span>
|
||||
<span class="badge bg-warning">{{ stats.warning }}</span>
|
||||
<span class="badge bg-danger">{{ stats.failure }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
|
Loading…
Reference in New Issue
Block a user