Add a legacy version for older versions of Django.

Signed-off-by: Chris Lamb <chris@thread.com>
If we see a DatabaseError, completely abort by disconnecting.

This prevents a stale database connection causing every subsequent queue
job to fail (!)

Signed-off-by: Chris Lamb <chris@thread.com>