Class: Dynflow::Coordinator::SingletonActionLock
- Inherits:
-
Lock
- Object
- Serializable
- Record
- Lock
- Dynflow::Coordinator::SingletonActionLock
- Defined in:
- lib/dynflow/coordinator.rb
Overview
Used when there should be only one execution plan for a given action class
Constant Summary
Constants inherited from Serializable
Serializable::LEGACY_TIME_FORMAT, Serializable::TIME_FORMAT
Instance Attribute Summary
Attributes inherited from Record
Class Method Summary collapse
- .lock_id(action_class) ⇒ Object
- .unique_filter(action_class) ⇒ Object
- .valid_classes ⇒ Object
- .valid_owner_ids(coordinator) ⇒ Object
Instance Method Summary collapse
-
#initialize(action_class, execution_plan_id) ⇒ SingletonActionLock
constructor
A new instance of SingletonActionLock.
- #owner_id ⇒ Object
Methods inherited from Lock
constantize, #to_s, #unlock_on_shutdown?, #validate!
Methods inherited from Record
#==, constantize, #from_hash, #hash, #id, new_from_hash, #to_hash, #to_s, #validate!
Methods inherited from Serializable
constantize, from_hash, new_from_hash, #to_hash
Constructor Details
#initialize(action_class, execution_plan_id) ⇒ SingletonActionLock
Returns a new instance of SingletonActionLock.
237 238 239 240 241 242 |
# File 'lib/dynflow/coordinator.rb', line 237 def initialize(action_class, execution_plan_id) super @data[:owner_id] = "execution-plan:#{execution_plan_id}" @data[:execution_plan_id] = execution_plan_id @data[:id] = self.class.lock_id(action_class) end |
Class Method Details
.lock_id(action_class) ⇒ Object
252 253 254 |
# File 'lib/dynflow/coordinator.rb', line 252 def self.lock_id(action_class) 'singleton-action:' + action_class end |
.unique_filter(action_class) ⇒ Object
248 249 250 |
# File 'lib/dynflow/coordinator.rb', line 248 def self.unique_filter(action_class) { :class => self.name, :id => self.lock_id(action_class) } end |
.valid_classes ⇒ Object
264 265 266 |
# File 'lib/dynflow/coordinator.rb', line 264 def self.valid_classes [self] end |
.valid_owner_ids(coordinator) ⇒ Object
256 257 258 259 260 261 262 |
# File 'lib/dynflow/coordinator.rb', line 256 def self.valid_owner_ids(coordinator) lock_ids = coordinator.find_locks(:class => self.name).map(&:owner_id) plans = coordinator.adapter.find_execution_plans(:uuid => lock_ids) plans = Hash[*plans.map { |plan| [plan[:uuid], plan[:state]] }.flatten] lock_ids.select { |id| plans.key?(id) && !%w(stopped paused).include?(plans[id]) } .map { |id| 'execution-plan:' + id } end |
Instance Method Details
#owner_id ⇒ Object
244 245 246 |
# File 'lib/dynflow/coordinator.rb', line 244 def owner_id @data[:execution_plan_id] end |