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
      6 7 8  | 
    
      # File 'lib/dynflow/action/singleton.rb', line 6 def self.included(base) base.middleware.use ::Dynflow::Middleware::Common::Singleton end  | 
  
Instance Method Details
#error!(*args) ⇒ Object
      39 40 41 42  | 
    
      # File 'lib/dynflow/action/singleton.rb', line 39 def error!(*args) singleton_unlock! super end  | 
  
#holds_singleton_lock? ⇒ Boolean
      24 25 26 27 28 29  | 
    
      # File 'lib/dynflow/action/singleton.rb', line 24 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
      35 36 37  | 
    
      # File 'lib/dynflow/action/singleton.rb', line 35 def singleton_lock singleton_lock_class.new(self.class.name, execution_plan_id) end  | 
  
#singleton_lock! ⇒ Object
      14 15 16 17 18  | 
    
      # File 'lib/dynflow/action/singleton.rb', line 14 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
      31 32 33  | 
    
      # File 'lib/dynflow/action/singleton.rb', line 31 def singleton_lock_class ::Dynflow::Coordinator::SingletonActionLock end  | 
  
#singleton_unlock! ⇒ Object
      20 21 22  | 
    
      # File 'lib/dynflow/action/singleton.rb', line 20 def singleton_unlock! world.coordinator.release(singleton_lock) if holds_singleton_lock? end  | 
  
#validate_singleton_lock! ⇒ Object
      10 11 12  | 
    
      # File 'lib/dynflow/action/singleton.rb', line 10 def validate_singleton_lock! singleton_lock! unless holds_singleton_lock? end  |