Update job state in separate transactions

This is to solve a concurrency issue where sometimes a job's state isn't
set after the last task has been set to DONE or FAILED.