diff --git a/rq/worker.py b/rq/worker.py index e44aa9f..7841faa 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -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 = '' # 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)