# File lib/dynflow/action/singleton.rb, line 4 def self.included(base) base.middleware.use ::Dynflow::Middleware::Common::Singleton end
# File lib/dynflow/action/singleton.rb, line 37 def error!(*args) singleton_unlock! super end
# File lib/dynflow/action/singleton.rb, line 22 def holds_singleton_lock? # Get locks for this action, there should be none or one lock_filter = singleton_lock_class.unique_filter(self.class.name) present_locks = world.coordinator.find_locks lock_filter !present_locks.empty? && present_locks.first.owner_id == execution_plan_id end
# File lib/dynflow/action/singleton.rb, line 33 def singleton_lock singleton_lock_class.new(self.class.name, execution_plan_id) end
# File lib/dynflow/action/singleton.rb, line 12 def singleton_lock! world.coordinator.acquire(singleton_lock) rescue Dynflow::Coordinator::LockError fail "Action #{self.class.name} is already active" end
# File lib/dynflow/action/singleton.rb, line 29 def singleton_lock_class ::Dynflow::Coordinator::SingletonActionLock end
# File lib/dynflow/action/singleton.rb, line 18 def singleton_unlock! world.coordinator.release(singleton_lock) if holds_singleton_lock? end
# File lib/dynflow/action/singleton.rb, line 8 def validate_singleton_lock! singleton_lock! unless holds_singleton_lock? end