more gracefully account for undefined stdout

* It's possible to have an exception raised in BaseTask.run() before the
stdout handler gets defined. This is problematic when the exception
handler tries to access that undefined var .. causing another exception.
Note that the second exception is caught also but it's not desirable to
lose the first exception.
* This fix checks to see if the stdout handler var is defined before
calling it's methods. Thus, we retain the original error message.
This commit is contained in:
chris meyers 2018-04-02 11:41:30 -04:00
parent 47fa99d3ad
commit 7e7ff8137d

View File

@ -993,9 +993,10 @@ class BaseTask(LogErrorsTask):
logger.exception('%s Exception occurred while running task', instance.log_format)
finally:
try:
stdout_handle.flush()
stdout_handle.close()
event_ct = getattr(stdout_handle, '_event_ct', 0)
if stdout_handle:
stdout_handle.flush()
stdout_handle.close()
event_ct = getattr(stdout_handle, '_event_ct', 0)
logger.info('%s finished running, producing %s events.',
instance.log_format, event_ct)
except Exception: