12510 review changes

This commit is contained in:
Arthur 2024-02-01 16:14:08 -08:00
parent c03cd6b2b9
commit c9f8b78048
2 changed files with 7 additions and 12 deletions

View File

@ -34,22 +34,15 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
def _output_results(job): def _output_results(job):
# Report on success/failure
if job.status == JobStatusChoices.STATUS_FAILED:
status = self.style.ERROR('FAILED')
elif job == JobStatusChoices.STATUS_ERRORED:
status = self.style.ERROR('ERRORED')
else:
status = self.style.SUCCESS('SUCCESS')
for test_name, attrs in job.data.logs.items(): for test_name, attrs in job.data['logs'].items():
self.stdout.write( self.stdout.write(
"\t{}: {} success, {} info, {} warning, {} failure".format( "\t{}: {} success, {} info, {} warning, {} failure".format(
test_name, attrs['success'], attrs['info'], attrs['warning'], attrs['failure'] test_name, attrs['success'], attrs['info'], attrs['warning'], attrs['failure']
) )
) )
def _set_job_data(job, script): def _set_job_data(script):
logs = script._logs logs = script._logs
job.data = { job.data = {
'logs': logs, 'logs': logs,
@ -71,7 +64,7 @@ class Command(BaseCommand):
except AbortTransaction: except AbortTransaction:
script.log_info("Database changes have been reverted automatically.") script.log_info("Database changes have been reverted automatically.")
clear_events.send(request) clear_events.send(request)
job = _set_job_data(job, script) _set_job_data(script)
job.terminate() job.terminate()
except Exception as e: except Exception as e:
stacktrace = traceback.format_exc() stacktrace = traceback.format_exc()
@ -81,9 +74,10 @@ class Command(BaseCommand):
script.log_info("Database changes have been reverted due to error.") script.log_info("Database changes have been reverted due to error.")
logger.error(f"Exception raised during script execution: {e}") logger.error(f"Exception raised during script execution: {e}")
clear_events.send(request) clear_events.send(request)
job = _set_job_data(job, script) _set_job_data(script)
job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=repr(e)) job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=repr(e))
_output_results(job)
logger.info(f"Script completed in {job.duration}") logger.info(f"Script completed in {job.duration}")
User = get_user_model() User = get_user_model()
@ -92,6 +86,7 @@ class Command(BaseCommand):
script = options['script'] script = options['script']
loglevel = options['loglevel'] loglevel = options['loglevel']
commit = options['commit'] commit = options['commit']
try: try:
data = json.loads(options['data']) data = json.loads(options['data'])
except TypeError: except TypeError:

View File

@ -660,7 +660,7 @@ def run_script(data, job, request=None, commit=True, **kwargs):
else: else:
script.log_info(msg) script.log_info(msg)
job = set_job_data(job, script) job = set_job_data(script)
job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=repr(e)) job.terminate(status=JobStatusChoices.STATUS_ERRORED, error=repr(e))
if request: if request:
clear_events.send(request) clear_events.send(request)