Log failed jobs exceptions.

This fixes issue #6203. It basically allows exceptions and their error messages to be logged to the database. Makes it 123450x easier to debug failed jobs. Tests also pass.

I pinged you on IRC but received no response. I'll leave this here until I can get a hold of you.
Please move this to the top of the list of imports.