Class: VCloudCloud::Transaction
- Inherits:
-
Object
- Object
- VCloudCloud::Transaction
- Defined in:
- lib/cloud/vcloud/steps.rb
Overview
Transactional step execution engine
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, client) ⇒ Transaction
constructor
A new instance of Transaction.
- #next(step_class, *args, &block) ⇒ Object
- #perform(options = {}, &block) ⇒ Object
Constructor Details
#initialize(name, client) ⇒ Transaction
Returns a new instance of Transaction.
25 26 27 28 29 30 31 |
# File 'lib/cloud/vcloud/steps.rb', line 25 def initialize(name, client) @name = name @client = client @logger = client.logger @state = {} @steps = [] end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
23 24 25 |
# File 'lib/cloud/vcloud/steps.rb', line 23 def client @client end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/cloud/vcloud/steps.rb', line 23 def name @name end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
23 24 25 |
# File 'lib/cloud/vcloud/steps.rb', line 23 def state @state end |
Class Method Details
.perform(name, client = nil, options = {}, &block) ⇒ Object
57 58 59 |
# File 'lib/cloud/vcloud/steps.rb', line 57 def self.perform(name, client = nil, = {}, &block) new(name, client).perform , &block end |
Instance Method Details
#next(step_class, *args, &block) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/cloud/vcloud/steps.rb', line 33 def next(step_class, *args, &block) step = step_class.new @state, @client @steps << step @logger.debug "STEP #{step_class.to_s}" step.perform *args, &block end |
#perform(options = {}, &block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cloud/vcloud/steps.rb', line 40 def perform( = {}, &block) with_thread_name @name do # Perform all steps guarded by exception handler begin block.call self rescue => ex @logger.error "FAIL #{@name} #{ex}" reverse_steps :rollback raise ex unless [:no_throws] @state[:error] = ex ensure reverse_steps :cleanup end end @state end |