Module: Dynflow::Action::Singleton
- Defined in:
- lib/dynflow/action/singleton.rb
Class Method Summary collapse
Instance Method Summary collapse
- #error!(*args) ⇒ Object
- #holds_singleton_lock? ⇒ Boolean
- #singleton_lock ⇒ Object
- #singleton_lock! ⇒ Object
- #singleton_lock_class ⇒ Object
- #singleton_unlock! ⇒ Object
- #validate_singleton_lock! ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 |
# File 'lib/dynflow/action/singleton.rb', line 5 def self.included(base) base.middleware.use ::Dynflow::Middleware::Common::Singleton end |
Instance Method Details
#error!(*args) ⇒ Object
38 39 40 41 |
# File 'lib/dynflow/action/singleton.rb', line 38 def error!(*args) singleton_unlock! super end |
#holds_singleton_lock? ⇒ Boolean
23 24 25 26 27 28 |
# File 'lib/dynflow/action/singleton.rb', line 23 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 |
#singleton_lock ⇒ Object
34 35 36 |
# File 'lib/dynflow/action/singleton.rb', line 34 def singleton_lock singleton_lock_class.new(self.class.name, execution_plan_id) end |
#singleton_lock! ⇒ Object
13 14 15 16 17 |
# File 'lib/dynflow/action/singleton.rb', line 13 def singleton_lock! world.coordinator.acquire(singleton_lock) rescue Dynflow::Coordinator::LockError fail "Action #{self.class.name} is already active" end |
#singleton_lock_class ⇒ Object
30 31 32 |
# File 'lib/dynflow/action/singleton.rb', line 30 def singleton_lock_class ::Dynflow::Coordinator::SingletonActionLock end |
#singleton_unlock! ⇒ Object
19 20 21 |
# File 'lib/dynflow/action/singleton.rb', line 19 def singleton_unlock! world.coordinator.release(singleton_lock) if holds_singleton_lock? end |
#validate_singleton_lock! ⇒ Object
9 10 11 |
# File 'lib/dynflow/action/singleton.rb', line 9 def validate_singleton_lock! singleton_lock! unless holds_singleton_lock? end |