dynflow 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -49,9 +49,9 @@ module Dynflow
49
49
  nil
50
50
  end
51
51
 
52
- ERROR = Object.new
53
- SUSPEND = Object.new
54
- Phase = Algebrick.type do
52
+ ERROR = Object.new
53
+ SUSPEND = Object.new
54
+ Phase = Algebrick.type do
55
55
  Executable = type do
56
56
  variants Plan = atom,
57
57
  Run = atom,
@@ -140,10 +140,11 @@ module Dynflow
140
140
  end
141
141
  end
142
142
 
143
- def set_plan_context(execution_plan, trigger)
143
+ def set_plan_context(execution_plan, trigger, from_subscription)
144
144
  phase! Plan
145
- @execution_plan = Type! execution_plan, ExecutionPlan
146
- @trigger = Type! trigger, Action, NilClass
145
+ @execution_plan = Type! execution_plan, ExecutionPlan
146
+ @trigger = Type! trigger, Action, NilClass
147
+ @from_subscription = Type! from_subscription, TrueClass, FalseClass
147
148
  end
148
149
 
149
150
  def trigger
@@ -151,6 +152,11 @@ module Dynflow
151
152
  @trigger
152
153
  end
153
154
 
155
+ def from_subscription?
156
+ phase! Plan
157
+ @from_subscription
158
+ end
159
+
154
160
  def execution_plan
155
161
  phase! Plan, Present
156
162
  @execution_plan
@@ -271,7 +277,7 @@ module Dynflow
271
277
  # Use #plan_self and #plan_action methods to plan actions.
272
278
  # It can use DB in this phase.
273
279
  def plan(*args)
274
- if trigger
280
+ if from_subscription?
275
281
  # if the action is triggered by subscription, by default use the
276
282
  # input of parent action.
277
283
  # should be replaced by referencing the input from input format
@@ -340,7 +346,7 @@ module Dynflow
340
346
 
341
347
  def plan_action(action_class, *args)
342
348
  phase! Plan
343
- @execution_plan.add_plan_step(action_class, self).execute(@execution_plan, nil, *args)
349
+ @execution_plan.add_plan_step(action_class, self).execute(@execution_plan, self, false, *args)
344
350
  end
345
351
 
346
352
  # DSL for run phase
@@ -358,7 +364,7 @@ module Dynflow
358
364
  throw ERROR
359
365
  end
360
366
 
361
- def with_error_handling(&block)
367
+ def with_error_handling(propagate_error = nil, &block)
362
368
  raise "wrong state #{self.state}" unless [:skipping, :running].include?(self.state)
363
369
 
364
370
  begin
@@ -378,6 +384,10 @@ module Dynflow
378
384
  else
379
385
  raise "wrong state #{self.state}"
380
386
  end
387
+
388
+ if propagate_error && self.state == :error
389
+ raise(@step.error.exception)
390
+ end
381
391
  end
382
392
 
383
393
  def set_error(error)
@@ -392,7 +402,10 @@ module Dynflow
392
402
  phase! Plan
393
403
  self.state = :running
394
404
  save_state
395
- with_error_handling do
405
+
406
+ # when the error occurred inside the planning, catch that
407
+ # before getting out of the planning phase
408
+ with_error_handling(!root_action?) do
396
409
  concurrence do
397
410
  world.middleware.execute(:plan, self, *args) do |*new_args|
398
411
  plan(*new_args)
@@ -407,7 +420,7 @@ module Dynflow
407
420
  @execution_plan.switch_flow(Flows::Concurrence.new([trigger_flow].compact)) do
408
421
  subscribed_actions.each do |action_class|
409
422
  new_plan_step = @execution_plan.add_plan_step(action_class, self)
410
- new_plan_step.execute(@execution_plan, self, *args)
423
+ new_plan_step.execute(@execution_plan, self, true, *args)
411
424
  end
412
425
  end
413
426
  end
@@ -475,5 +488,9 @@ module Dynflow
475
488
  value.replace not_serializable: true
476
489
  raise e
477
490
  end
491
+
492
+ def root_action?
493
+ @trigger.nil?
494
+ end
478
495
  end
479
496
  end
@@ -152,7 +152,7 @@ module Dynflow
152
152
  world.transaction_adapter.transaction do
153
153
  world.middleware.execute(:plan_phase, root_plan_step.action_class) do
154
154
  with_planning_scope do
155
- root_plan_step.execute(self, nil, *args)
155
+ root_plan_step.execute(self, nil, false, *args)
156
156
 
157
157
  if @dependency_graph.unresolved?
158
158
  raise "Some dependencies were not resolved: #{@dependency_graph.inspect}"
@@ -36,11 +36,11 @@ module Dynflow
36
36
  end
37
37
 
38
38
  # @return [Action]
39
- def execute(execution_plan, trigger, *args)
39
+ def execute(execution_plan, trigger, from_subscription, *args)
40
40
  unless @action
41
41
  raise "The action was not initialized, you might forgot to call initialize_action method"
42
42
  end
43
- @action.set_plan_context(execution_plan, trigger)
43
+ @action.set_plan_context(execution_plan, trigger, from_subscription)
44
44
  Type! execution_plan, ExecutionPlan
45
45
  with_meta_calculation(@action) do
46
46
  @action.execute(*args)
@@ -10,7 +10,7 @@ module Dynflow
10
10
  Testing.get_id.to_s, Testing.get_id, Testing.get_id)
11
11
  end
12
12
 
13
- def execute(execution_plan, event, *args)
13
+ def execute(execution_plan, event, from_subscription, *args)
14
14
  @plan_input = args
15
15
  self
16
16
  end
@@ -16,7 +16,7 @@ module Dynflow
16
16
  run_step_id: nil,
17
17
  finalize_step_id: nil },
18
18
  execution_plan.world).tap do |action|
19
- action.set_plan_context(execution_plan, trigger)
19
+ action.set_plan_context(execution_plan, trigger, false)
20
20
  end
21
21
  end
22
22
 
@@ -18,6 +18,9 @@ module Dynflow
18
18
 
19
19
  def mimic!(*types)
20
20
  define =-> _ do
21
+ define_method :mimic_types do
22
+ types
23
+ end
21
24
  define_method :kind_of? do |type|
22
25
  types.any? { |t| t <= type } || super(type)
23
26
  end
@@ -1,3 +1,3 @@
1
1
  module Dynflow
2
- VERSION = '0.7.4'
2
+ VERSION = '0.7.5'
3
3
  end
@@ -166,6 +166,16 @@ module Dynflow
166
166
 
167
167
  end
168
168
 
169
+ describe 'error in planning phase' do
170
+ let :execution_plan do
171
+ world.plan(Support::CodeWorkflowExample::IncomingIssues, [:fail] + issues_data)
172
+ end
173
+
174
+ it 'stops the planning right after the first error occurred' do
175
+ execution_plan.steps.size.must_equal 2
176
+ end
177
+ end
178
+
169
179
  describe 'multi dependencies' do
170
180
  let :execution_plan do
171
181
  world.plan(Support::CodeWorkflowExample::Commit, 'sha' => 'abc123')
@@ -50,6 +50,7 @@ module Support
50
50
  class IncomingIssue < Dynflow::Action
51
51
 
52
52
  def plan(issue)
53
+ raise "You want me to fail" if issue == :fail
53
54
  plan_self(issue)
54
55
  plan_action(Triage, issue)
55
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-19 00:00:00.000000000 Z
12
+ date: 2014-09-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport