Class: Dynflow::Coordinator::SingletonActionLock

Inherits:
Lock show all
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

#data

Class Method Summary collapse

Instance Method Summary collapse

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_classesObject



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_idObject



244
245
246
# File 'lib/dynflow/coordinator.rb', line 244

def owner_id
  @data[:execution_plan_id]
end