Commit d654e1e3 by jasl

refactor fire

parent 72f52db2
......@@ -52,6 +52,6 @@ gem "form_core"
gem "duck_record"
gem "closure_tree"
gem "cocoon"
gem "script_core", github: "rails-engine/script_core", submodules: true
gem "script_core"
gem "graphviz"
GIT
remote: https://github.com/rails-engine/script_core.git
revision: f086b63c03061732c8a760b97d54a9d2e7cbec68
submodules: true
specs:
script_core (0.0.4)
msgpack (~> 1.0)
rake-compiler (~> 1.0)
PATH
remote: .
specs:
......@@ -180,7 +171,7 @@ GEM
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
rubocop-rails_config (0.2.3)
rubocop-rails_config (0.2.5)
railties (>= 3.0)
rubocop (~> 0.56)
ruby-progressbar (1.10.0)
......@@ -196,6 +187,9 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
script_core (0.0.4)
msgpack (~> 1.0)
rake-compiler (~> 1.0)
selectize-rails (0.12.5)
sprockets (4.0.0.beta8)
concurrent-ruby (~> 1.0)
......@@ -248,7 +242,7 @@ DEPENDENCIES
rubocop
rubocop-rails_config
sass-rails
script_core!
script_core
selectize-rails
sprockets (~> 4.0.0.beta4)
sqlite3
......
......@@ -11,8 +11,22 @@ module WorkflowCore
has_many :output_places, dependent: :destroy,
foreign_key: "input_transition_id", class_name: "WorkflowCore::Place"
def fire(_token)
def fire(token, transaction_options: {requires_new: true}, **options)
transaction(**transaction_options) do
on_fire(token, transaction_options, options)
end
rescue => ex
rescue_fire_error ex
end
protected
def on_fire(_token, _transaction_options, **_options)
raise NotImplementedError
end
def rescue_fire_error(ex)
raise ex
end
end
end
......@@ -3,14 +3,6 @@
class Transition < WorkflowCore::Transition
serialize :options, Transitions::Options::Common
def auto_forward(next_token)
transition = next_token.place.output_transition
return unless transition
return unless transition.auto_forwardable?
transition.fire(next_token)
end
def auto_forwardable?
false
end
......@@ -45,6 +37,16 @@ class Transition < WorkflowCore::Transition
g
end
protected
def auto_forward(next_token, transaction_options, **options)
transition = next_token.place.output_transition
return unless transition
return unless transition.auto_forwardable?
transition.on_fire(next_token, transaction_options, options)
end
end
require_dependency "transitions"
# frozen_string_literal: true
class Transitions::End < Transition
def fire(token)
def on_fire(token, _transaction_options, **_options)
p = output_places.first # assume only one output place
token.completed!
......
......@@ -3,24 +3,24 @@
class Transitions::ExclusiveChoice < Transition
serialize :options, Transitions::Options::ExclusiveChoice
def fire(token)
def on_fire(token, transaction_options, **options)
instance = token.instance
next_place_id = options.conditions.select do |condition|
next_place_id = self.options.conditions.select do |condition|
r = ScriptCore.run input: {payload: instance.payload},
sources: [["expression", "@output = #{condition.condition_expression}"]]
if r.errors.any?
raise r.errors.map(&:message).join("; ")
end
r.output
end.first&.place_id || options.default_next_place_id
end.first&.place_id || self.options.default_next_place_id
next_place = workflow.places.find(next_place_id)
token.completed!
next_token = next_place.tokens.create! previous: token, type: "Token",
instance: token.instance, workflow: workflow
auto_forward(next_token)
auto_forward(next_token, transaction_options, options)
end
def auto_forwardable?
......
# frozen_string_literal: true
class Transitions::ParallelSplit < Transition
def fire(token)
def on_fire(token, transaction_options, **options)
token.completed!
output_places.each do |p|
next_token = p.tokens.create! previous: token, type: "Token",
instance: token.instance, workflow: workflow
auto_forward(next_token)
auto_forward(next_token, transaction_options, options)
end
def auto_forwardable?
......
# frozen_string_literal: true
class Transitions::Sequence < Transition
def fire(token)
def on_fire(token, transaction_options, **options)
p = output_places.first # assume only one output place
token.completed!
next_token = p.tokens.create! previous: token, type: "Token",
instance: token.instance, workflow: workflow
auto_forward(next_token)
auto_forward(next_token, transaction_options, options)
end
end
# frozen_string_literal: true
class Transitions::SimpleMerge < Transition
def fire(token)
def on_fire(token, transaction_options, **options)
p = output_places.first # assume only one output place
# return unless p.tokens.size.zero?
......@@ -14,7 +14,7 @@ class Transitions::SimpleMerge < Transition
if completed_tokens.size == 1
next_token = p.tokens.create! previous: token, type: "Token",
instance: token.instance, workflow: workflow
auto_forward(next_token)
auto_forward(next_token, transaction_options, options)
end
end
......
......@@ -3,12 +3,12 @@
class Transitions::Start < Transition
# http://workflowpatterns.com/patterns/control/basic/wcp1.php
def fire(token)
def on_fire(token, transaction_options, **options)
p = output_places.first # assume only one output place
token.completed!
next_token = p.tokens.create! previous: token, type: "Token",
instance: token.instance, workflow: workflow
auto_forward(next_token)
auto_forward(next_token, transaction_options, options)
end
end
# frozen_string_literal: true
class Transitions::Synchronization < Transition
def fire(token)
def on_fire(token, transaction_options, **options)
p = output_places.first # assume only one output place
# return unless p.tokens.size.zero?
......@@ -14,7 +14,7 @@ class Transitions::Synchronization < Transition
if completed_tokens.size == input_places.size
next_token = p.tokens.create! previous: token, type: "Token",
instance: token.instance, workflow: workflow
auto_forward(next_token)
auto_forward(next_token, transaction_options, options)
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment