Fix retry logic for batch import errors

Assigning this to @lcdhoffman.

I think catching the Sequel::DatabaseError exception was stopping the "retriable exception" logic from firing.  The call to DB.open() should cause the whole transaction to be retried up to 5 times when one of these errors occurs, so hopefully that's enough.

I've shuffled the begin/ensure blocks around to make sure that the ensure actions till runs when a DatabaseError is thrown.  Hopefully that's still right.