As noted above, we can guard against a race condition by doing an upsert here, and only setting (with the ```$set``` operator) the task_id and state.