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
Show replies by date
---
src/app/util/taskomatic.rb | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/app/util/taskomatic.rb b/src/app/util/taskomatic.rb
index b8a7809..5b8dd97 100644
--- a/src/app/util/taskomatic.rb
+++ b/src/app/util/taskomatic.rb
@@ -70,7 +70,7 @@ module Taskomatic
task.state = Task::STATE_FAILED
task.message = ex.message
ensure
- task.save!
+ task.save! if Task.exists?(task.id)
end
end
--
1.7.6.5