Class: FlowCore::Step

Inherits:
ApplicationRecord show all
Extended by:
ActiveRecord::Acts::List::ClassMethods, Ancestry::HasAncestry
Defined in:
app/models/flow_core/step.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#append_toObject

Returns the value of attribute append_to.



65
66
67
# File 'app/models/flow_core/step.rb', line 65

def append_to
  @append_to
end

Class Method Details

.barrier_step?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'app/models/flow_core/step.rb', line 192

def barrier_step?
  false
end

.branch_arc_guard_attachable?Boolean

Returns:

  • (Boolean)


204
205
206
# File 'app/models/flow_core/step.rb', line 204

def branch_arc_guard_attachable?
  false
end

.branch_configurable?Boolean

Returns:

  • (Boolean)


212
213
214
# File 'app/models/flow_core/step.rb', line 212

def branch_configurable?
  false
end

.fallback_branch_required?Boolean

Returns:

  • (Boolean)


220
221
222
# File 'app/models/flow_core/step.rb', line 220

def fallback_branch_required?
  false
end

.multi_branch_step?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'app/models/flow_core/step.rb', line 184

def multi_branch_step?
  false
end

.redirection_configurable?Boolean

Returns:

  • (Boolean)


208
209
210
# File 'app/models/flow_core/step.rb', line 208

def redirection_configurable?
  false
end

.redirection_step?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'app/models/flow_core/step.rb', line 188

def redirection_step?
  false
end

.transition_callback_attachable?Boolean

Returns:

  • (Boolean)


200
201
202
# File 'app/models/flow_core/step.rb', line 200

def transition_callback_attachable?
  !multi_branch_step?
end

.transition_trigger_attachable?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'app/models/flow_core/step.rb', line 196

def transition_trigger_attachable?
  !multi_branch_step? && !redirection_step?
end

.transition_trigger_required?Boolean

Returns:

  • (Boolean)


216
217
218
# File 'app/models/flow_core/step.rb', line 216

def transition_trigger_required?
  false
end

Instance Method Details

#barrier_step?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/models/flow_core/step.rb', line 79

def barrier_step?
  self.class.barrier_step?
end

#branch_arc_guard_attachable?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'app/models/flow_core/step.rb', line 91

def branch_arc_guard_attachable?
  self.class.branch_arc_guard_attachable?
end

#branch_configurable?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'app/models/flow_core/step.rb', line 107

def branch_configurable?
  self.class.branch_configurable?
end

#deploy_to_workflow!(_workflow, _input_place_or_transition) ⇒ Object

Raises:

  • (NotImplementedError)


67
68
69
# File 'app/models/flow_core/step.rb', line 67

def deploy_to_workflow!(_workflow, _input_place_or_transition)
  raise NotImplementedError
end

#fallback_branch_required?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/models/flow_core/step.rb', line 95

def fallback_branch_required?
  self.class.fallback_branch_required?
end

#multi_branch_step?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'app/models/flow_core/step.rb', line 75

def multi_branch_step?
  self.class.multi_branch_step?
end

#redirectable_stepsObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'app/models/flow_core/step.rb', line 111

def redirectable_steps
  return [] unless redirection_step?

  redirectable_steps = []

  # Barrier step is the stop point, beyond if can't ensure the workflow valid
  # e.g. consider there's a redirection step in one of branch of a parallel branch step,
  # the parallel branch step is the barrier step, if redirect beyond the barrier step,
  # it will multiplex all branches again and again
  # Barrier step 是保障流程的边界,如果重定向到边界外的节点,就无法保证流程合法,
  # 一个例子是假设并发分支步骤的某个分支里有一个重定向节点,并发分支步骤就是一个 Barrier Step,
  # 如果可以重定向到并发分支步骤外,重定向到步骤后会重新执行这个并发分支步骤,导致其他分支的步骤会被无限重复执行
  ancestors.reverse_each do |step|
    break if step.barrier_step?

    redirectable_steps << step
  end

  # return an empty array if there's no safe ancestor,
  # redirect to steps which in current branch in not safe, because it will infinite loop
  # 如果一个安全的祖先步骤都没有,就返回空集,跳到当前分支的步骤会导致死循环或者死代码,没有意义
  return [] if redirectable_steps.empty?

  # if the redirection step is the first step of a branch,
  # avoiding redirect to parent and ancestors which are first step (of a branch) and without a transition trigger,
  # because it will lead infinite loop,
  # 如果重定向步骤是分支的第一步,那么父步骤和其他也是处于(分支)第一步的祖先,也都要避免跳转,因为会导致死循环
  if position == 1 && redirectable_steps.any?
    if redirectable_steps.first.multi_branch_step? && !redirectable_steps.first.transition_trigger
      redirectable_steps.shift
    end

    while redirectable_steps.any?
      step = redirectable_steps.first
      if step.multi_branch_step? && !redirectable_steps.first.transition_trigger
        redirectable_steps.shift

        if step.position > 1
          break
        end
      else
        break
      end
    end
  end

  # It's safe to redirect to any top level (or main branch) steps,
  # just avoiding the redirect step's ancestor, because it may lead infinite loop
  # 跳到顶层(或者说主干)步骤都是安全的,只是要去掉跳转步骤的祖先,因为会导致死循环
  if redirectable_steps.reject!(&:root?)
    redirectable_steps.concat(pipeline.steps)
  elsif redirectable_steps.empty?
    redirectable_steps.concat(pipeline.steps - ancestors)
  end

  # It's also safe to redirect to any of children steps,
  # just avoid current branch which the redirection step belongs to.
  # 跳转到任何步骤的分支也都是安全的,就是要避免分支是当前跳转步骤的祖先步骤
  redirectable_steps.map! do |s|
    if s.parent_of? self
      [s].concat s.children.where.not(branch_id: branch_id)
    else
      [s].concat s.children
    end
  end
  redirectable_steps.flatten!
  redirectable_steps.uniq!
  redirectable_steps.reject!(&:redirection_step?)

  redirectable_steps
end

#redirection_configurable?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'app/models/flow_core/step.rb', line 103

def redirection_configurable?
  self.class.redirection_configurable?
end

#redirection_step?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'app/models/flow_core/step.rb', line 71

def redirection_step?
  self.class.redirection_step?
end

#transition_callback_attachable?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/models/flow_core/step.rb', line 87

def transition_callback_attachable?
  self.class.transition_callback_attachable?
end

#transition_trigger_attachable?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'app/models/flow_core/step.rb', line 83

def transition_trigger_attachable?
  self.class.transition_trigger_attachable?
end

#transition_trigger_required?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'app/models/flow_core/step.rb', line 99

def transition_trigger_required?
  self.class.transition_trigger_required?
end