Locking task rows using FOR UPDATE

This will prevent actions on tasks to be done twice.