[PATCH 0/1 conductor] BZ 784499 add check to ensure task exists before saving
Tzu-Mainn Chen
tzumainn at redhat.com
Fri Feb 3 15:09:18 UTC 2012
Here's the original situation:
begin
.
.
.
task.instance.state = dcloud_to_instance_state(dcloud_instance.state)
task.instance.save!
task.state = Task::STATE_FINISHED
rescue Exception => ex
task.state = Task::STATE_FAILED
task.message = ex.message
ensure
task.save!
end
Due to optimistic locking, the above code gives stale object exceptions if the task is successfully deleted. My understanding is that this is because the after_save method in instance_observer.rb will (under certain circumstances), delete itself and its tasks, meaning task.save! will fail.
The patch replaces
task.save!
with
task.save! if Task.exists?(task.id)
If there's a better way to handle this (or if my logic is wrong), please let me know!
Mainn
More information about the aeolus-devel
mailing list