Don't log job exceptions twice (#1746)

* Don't log job exceptions twice

* Preserve traceback while encountering deserialization error
This commit is contained in:
Selwin Ong 2023-01-08 13:11:33 +07:00 committed by GitHub
parent 62acd56c91
commit d0e832181f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -1164,6 +1164,7 @@ class Worker:
def handle_exception(self, job: 'Job', *exc_info):
"""Walks the exception handler stack to delegate exception handling."""
exc_string = ''.join(traceback.format_exception(*exc_info))
# If the job cannot be deserialized, it will raise when func_name or
@ -1175,14 +1176,17 @@ class Worker:
'arguments': job.args,
'kwargs': job.kwargs,
}
func_name = job.func_name
except DeserializationError:
extra = {}
func_name = '<DeserializationError>'
# the properties below should be safe however
extra.update({'queue': job.origin, 'job_id': job.id})
# func_name
self.log.error(exc_string, exc_info=True, extra=extra)
self.log.error(f'[Job {job.id}]: exception raised while executing ({func_name})\n' + exc_string,
extra=extra)
for handler in self._exc_handlers:
self.log.debug('Invoking exception handler %s', handler)