Optimistic locking on job completion.

Impossible to test properly with Postgres. Horrible partially correct
test.