flow_core 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class CreateFlowCoreTables < ActiveRecord::Migration[6.0]
3
+ class CreateWorkflowTables < ActiveRecord::Migration[6.0]
4
4
  def change
5
5
  create_table :flow_core_workflows do |t|
6
6
  t.string :name, null: false
@@ -30,64 +30,67 @@ class CreateFlowCoreTables < ActiveRecord::Migration[6.0]
30
30
 
31
31
  t.string :name
32
32
  t.string :tag
33
+ t.integer :output_token_create_strategy, null: false, default: 0, comment: "0-petri_net"
34
+ t.integer :auto_finish_strategy, null: false, default: 0, comment: "0-disabled"
33
35
 
34
36
  t.timestamps
35
37
  end
36
38
 
37
- create_table :flow_core_transition_callbacks do |t|
39
+ create_table :flow_core_arcs do |t|
38
40
  t.references :workflow, null: false, foreign_key: { to_table: :flow_core_workflows }
39
41
  t.references :transition, null: false, foreign_key: { to_table: :flow_core_transitions }
42
+ t.references :place, null: false, foreign_key: { to_table: :flow_core_places }
40
43
 
41
- t.string :configuration
42
- t.string :type
44
+ t.integer :direction, null: false, default: 0, comment: "0-in, 1-out"
45
+ t.boolean :fallback_arc, null: false, default: false
43
46
 
44
47
  t.timestamps
45
48
  end
46
49
 
47
- create_table :flow_core_transition_triggers do |t|
50
+ create_table :flow_core_instances do |t|
48
51
  t.references :workflow, null: false, foreign_key: { to_table: :flow_core_workflows }
49
- t.references :transition, null: false, foreign_key: { to_table: :flow_core_transitions }
50
52
 
51
- t.text :configuration
52
- t.string :type
53
+ t.string :tag, index: { unique: true }
53
54
 
54
- t.timestamps
55
- end
55
+ t.integer :stage, default: 0, comment: "0-created, 1-activated, 2-canceled, 3-finished, 4-terminated"
56
+ t.datetime :activated_at
57
+ t.datetime :finished_at
58
+ t.datetime :canceled_at
59
+ t.datetime :terminated_at
56
60
 
57
- create_table :flow_core_arcs do |t|
58
- t.references :workflow, null: false, foreign_key: { to_table: :flow_core_workflows }
59
- t.references :transition, null: false, foreign_key: { to_table: :flow_core_transitions }
60
- t.references :place, null: false, foreign_key: { to_table: :flow_core_places }
61
+ t.string :terminate_reason
61
62
 
62
- t.integer :direction, null: false, default: 0, comment: "0-in, 1-out"
63
+ t.text :payload
63
64
 
64
65
  t.timestamps
65
66
  end
66
67
 
67
- create_table :flow_core_arc_guards do |t|
68
- t.references :workflow, null: false, foreign_key: { to_table: :flow_core_workflows }
69
- t.references :arc, null: false, foreign_key: { to_table: :flow_core_arcs }
68
+ create_table :flow_core_transition_callbacks do |t|
69
+ t.references :workflow, foreign_key: { to_table: :flow_core_workflows }
70
+ t.references :transition, foreign_key: { to_table: :flow_core_transitions }
70
71
 
71
- t.text :configuration
72
+ t.string :configuration
72
73
  t.string :type
73
74
 
74
75
  t.timestamps
75
76
  end
76
77
 
77
- create_table :flow_core_instances do |t|
78
- t.references :workflow, null: false, foreign_key: { to_table: :flow_core_workflows }
78
+ create_table :flow_core_transition_triggers do |t|
79
+ t.references :workflow, foreign_key: { to_table: :flow_core_workflows }
80
+ t.references :transition, foreign_key: { to_table: :flow_core_transitions }
79
81
 
80
- t.string :tag, index: { unique: true }
82
+ t.text :configuration
83
+ t.string :type
81
84
 
82
- t.integer :stage, default: 0, comment: "0-created, 1-activated, 2-canceled, 3-finished, 4-terminated"
83
- t.datetime :activated_at
84
- t.datetime :finished_at
85
- t.datetime :canceled_at
86
- t.datetime :terminated_at
85
+ t.timestamps
86
+ end
87
87
 
88
- t.string :terminate_reason
88
+ create_table :flow_core_arc_guards do |t|
89
+ t.references :workflow, foreign_key: { to_table: :flow_core_workflows }
90
+ t.references :arc, foreign_key: { to_table: :flow_core_arcs }
89
91
 
90
- t.text :payload
92
+ t.text :configuration
93
+ t.string :type
91
94
 
92
95
  t.timestamps
93
96
  end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreatePipelineTables < ActiveRecord::Migration[6.0]
4
+ def change
5
+ create_table :flow_core_pipelines do |t|
6
+ t.string :name, null: false
7
+ t.string :type
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ create_table :flow_core_steps do |t|
13
+ t.references :pipeline, null: false, foreign_key: { to_table: :flow_core_pipelines }
14
+
15
+ t.string :ancestry, index: true
16
+ t.integer :position, null: false
17
+
18
+ t.string :name
19
+ t.string :type
20
+ t.boolean :verified, null: false, default: false
21
+
22
+ t.references :redirect_to_step, foreign_key: { to_table: :flow_core_steps }
23
+
24
+ t.timestamps
25
+ end
26
+
27
+ create_table :flow_core_branches do |t|
28
+ t.references :pipeline, null: false, foreign_key: { to_table: :flow_core_pipelines }
29
+ t.references :step, null: false, foreign_key: { to_table: :flow_core_steps }
30
+
31
+ t.string :name
32
+ t.boolean :fallback_branch, null: false, default: false
33
+
34
+ t.timestamps
35
+ end
36
+
37
+ change_table :flow_core_steps do |t|
38
+ t.references :branch, foreign_key: { to_table: :flow_core_branches }
39
+ end
40
+
41
+ change_table :flow_core_transition_triggers do |t|
42
+ t.references :pipeline, foreign_key: { to_table: :flow_core_pipelines }
43
+ t.references :step, foreign_key: { to_table: :flow_core_steps }
44
+ end
45
+
46
+ change_table :flow_core_transition_callbacks do |t|
47
+ t.references :pipeline, foreign_key: { to_table: :flow_core_pipelines }
48
+ t.references :step, foreign_key: { to_table: :flow_core_steps }
49
+ end
50
+
51
+ change_table :flow_core_arc_guards do |t|
52
+ t.references :pipeline, foreign_key: { to_table: :flow_core_pipelines }
53
+ t.references :branch, foreign_key: { to_table: :flow_core_branches }
54
+ end
55
+
56
+ change_table :flow_core_transitions do |t|
57
+ t.references :generated_by_step, foreign_key: { to_table: :flow_core_steps }
58
+ end
59
+
60
+ change_table :flow_core_workflows do |t|
61
+ t.references :generated_by_pipeline, foreign_key: { to_table: :flow_core_pipelines }
62
+ end
63
+ end
64
+ end
@@ -6,6 +6,9 @@ require "rgl/topsort"
6
6
  require "rgl/traversal"
7
7
  require "rgl/path"
8
8
 
9
+ require "acts_as_list"
10
+ require "ancestry"
11
+
9
12
  require "flow_core/engine"
10
13
 
11
14
  require "flow_core/errors"
@@ -18,9 +21,5 @@ require "flow_core/workflow_callbacks"
18
21
  require "flow_core/definition"
19
22
  require "flow_core/violations"
20
23
 
21
- ActiveSupport.on_load(:i18n) do
22
- I18n.load_path << File.expand_path("flow_core/locale/en.yml", __dir__)
23
- end
24
-
25
24
  module FlowCore
26
25
  end
@@ -67,7 +67,8 @@ module FlowCore::Definition
67
67
 
68
68
  workflow = nil
69
69
  FlowCore::ApplicationRecord.transaction do
70
- workflow = FlowCore::Workflow.create! attributes
70
+ workflow = FlowCore::Workflow.new attributes
71
+ workflow.save!
71
72
 
72
73
  # Places
73
74
  place_records = {}
@@ -97,9 +98,10 @@ module FlowCore::Definition
97
98
 
98
99
  td.output_tags.each do |output|
99
100
  arc = workflow.arcs.out.create! transition: transition_records[td.tag],
100
- place: place_records[output[:tag]]
101
- if output[:guard]
102
- arc.guards.create! output[:guard].compile
101
+ place: place_records[output[:tag]],
102
+ fallback_arc: output[:fallback]
103
+ output[:guards].each do |guard|
104
+ arc.guards.create! guard.compile
103
105
  end
104
106
  end
105
107
  end
@@ -3,6 +3,7 @@
3
3
  module FlowCore::Definition
4
4
  class Transition
5
5
  attr_reader :net, :tag, :attributes, :trigger, :callbacks, :input_tags, :output_tags
6
+
6
7
  private :net
7
8
 
8
9
  def initialize(net, tag, attributes = {}, &block)
@@ -19,8 +20,8 @@ module FlowCore::Definition
19
20
  output = attributes.delete(:output)
20
21
  raise ArgumentError, "Require `input`" unless input
21
22
 
22
- self.input input
23
- self.output output if output
23
+ inputs(*input)
24
+ outputs(*output) if output
24
25
 
25
26
  trigger = attributes.delete :with_trigger
26
27
  @trigger =
@@ -31,7 +32,7 @@ module FlowCore::Definition
31
32
  callbacks = []
32
33
  callbacks.concat Array.wrap(attributes.delete(:with_callbacks))
33
34
  callbacks.concat Array.wrap(attributes.delete(:with_callback))
34
- @callbacks = callbacks.map { |cb| FlowCore::Definition::Callback.new cb }
35
+ @callbacks = callbacks.compact.map { |cb| FlowCore::Definition::Callback.new cb }
35
36
 
36
37
  @attributes = attributes.with_indifferent_access.except(FlowCore::Transition::FORBIDDEN_ATTRIBUTES)
37
38
  @attributes[:name] ||= tag.to_s
@@ -54,42 +55,53 @@ module FlowCore::Definition
54
55
  end
55
56
  end
56
57
 
57
- def input(tag)
58
- places = Array.wrap(tag)
59
- places.each do |place|
60
- case place
58
+ def input(tag, attributes = {})
59
+ unless net.places.find { |place| place.tag == tag }
60
+ net.add_place(tag, attributes)
61
+ end
62
+
63
+ @input_tags << tag
64
+ end
65
+
66
+ def inputs(*tags)
67
+ tags.each do |tag|
68
+ case tag
61
69
  when Symbol
62
- net.add_place(place)
63
- tag = place
70
+ input(tag)
64
71
  when Array # Expect `[:p1, {name: "Place 1"}]`
65
- net.add_place(*place)
66
- tag = place.first
72
+ input(*tag)
67
73
  else
68
74
  raise TypeError, "Unknown pattern - #{place}"
69
75
  end
70
-
71
- @input_tags << tag
72
76
  end
73
77
  end
74
78
 
75
79
  def output(tag, attributes = {})
76
- guard = attributes.delete :with_guard
77
- guard = FlowCore::Definition::Guard.new(guard) if guard&.is_a?(Hash)
80
+ guards = []
81
+ guards.concat Array.wrap(attributes.delete(:with_guards))
82
+ guards.concat Array.wrap(attributes.delete(:with_guard))
83
+ guards.compact!
84
+ guards.map! { |guard| FlowCore::Definition::Guard.new guard }
78
85
 
79
- places = Array.wrap(tag)
80
- places.each do |place|
81
- case place
86
+ fallback = attributes.delete(:fallback) || false
87
+
88
+ unless net.places.find { |place| place.tag == tag }
89
+ net.add_place(tag, attributes)
90
+ end
91
+
92
+ @output_tags << { tag: tag, guards: guards, fallback: fallback }
93
+ end
94
+
95
+ def outputs(*tags)
96
+ tags.each do |tag|
97
+ case tag
82
98
  when Symbol
83
- net.add_place(place)
84
- tag = place
99
+ output(tag)
85
100
  when Array # Expect `[:p1, {name: "Place 1"}]`
86
- net.add_place(*place)
87
- tag = place.first
101
+ output(*tag)
88
102
  else
89
103
  raise TypeError, "Unknown pattern - #{place}"
90
104
  end
91
-
92
- @output_tags << { tag: tag, guard: guard }
93
105
  end
94
106
  end
95
107
 
@@ -100,7 +112,7 @@ module FlowCore::Definition
100
112
  trigger: @trigger&.compile,
101
113
  callbacks: @callbacks.map(&:compile),
102
114
  input_tags: @input_tags,
103
- output_tags: @output_tags.map { |output| { tag: output[:tag], guard: output[:guard]&.compile } }
115
+ output_tags: @output_tags.map { |output| { tag: output[:tag], guards: output[:guards].map(&:compile) } }
104
116
  }
105
117
  end
106
118
  end
@@ -2,5 +2,10 @@
2
2
 
3
3
  module FlowCore
4
4
  class Engine < ::Rails::Engine
5
+ initializer "flow_core.load_default_i18n" do
6
+ ActiveSupport.on_load(:i18n) do
7
+ I18n.load_path << File.expand_path("locale/en.yml", __dir__)
8
+ end
9
+ end
5
10
  end
6
11
  end
@@ -5,11 +5,11 @@ en:
5
5
  flow_core/place: Place
6
6
  flow_core/start_place: Start Place
7
7
  flow_core/end_place: End Place
8
- flow_core/transition: Workflow
9
- flow_core/transition_trigger: Transition Trigger
10
- flow_core/transition_callback: Trasition Callback
8
+ flow_core/transition: Transition
9
+ # flow_core/transition_trigger: Transition Trigger
10
+ # flow_core/transition_callback: Transition Callback
11
11
  flow_core/arc: Arc
12
- flow_core/arc_guard: Arc Guard
12
+ # flow_core/arc_guard: Arc Guard
13
13
  flow_core/instance: Instance
14
14
  flow_core/token: Token
15
15
  flow_core/task: Task
@@ -19,8 +19,13 @@ en:
19
19
  verified: Verified
20
20
  invalid: Invalid
21
21
  violations:
22
+ no_start_place: "No start place"
23
+ no_end_place: "No end place"
22
24
  format: "%{model} %{name} %{message}"
23
25
  unreachable: "Unreachable from start place"
24
26
  impassable: "Impassable to end place"
25
27
  trigger_unconfigure: "Trigger not configured yet"
26
28
  callback_unconfigure: "Callback not configured yet"
29
+ pipeline:
30
+ synchronization_transition_name: "Synchronization"
31
+ fallback_branch_name: "Default branch"
@@ -24,6 +24,10 @@ module FlowCore
24
24
  true
25
25
  end
26
26
 
27
+ def auto_finishable?
28
+ false
29
+ end
30
+
27
31
  protected
28
32
 
29
33
  def notify_workflow_task_finished!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FlowCore
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.5"
5
5
  end
@@ -4,6 +4,8 @@ module FlowCore
4
4
  module WorkflowCallbacks
5
5
  extend ActiveSupport::Concern
6
6
 
7
+ def on_instance_create_validation(_instance); end
8
+
7
9
  def on_instance_cancel(_instance); end
8
10
 
9
11
  def on_instance_activate(_instance); end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flow_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - jasl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-18 00:00:00.000000000 Z
11
+ date: 2020-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: acts_as_list
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ancestry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: rails
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,10 +94,18 @@ files:
66
94
  - app/models/flow_core/application_record.rb
67
95
  - app/models/flow_core/arc.rb
68
96
  - app/models/flow_core/arc_guard.rb
97
+ - app/models/flow_core/branch.rb
69
98
  - app/models/flow_core/end_place.rb
70
99
  - app/models/flow_core/instance.rb
100
+ - app/models/flow_core/pipeline.rb
71
101
  - app/models/flow_core/place.rb
72
102
  - app/models/flow_core/start_place.rb
103
+ - app/models/flow_core/step.rb
104
+ - app/models/flow_core/steps/end.rb
105
+ - app/models/flow_core/steps/exclusive_choice.rb
106
+ - app/models/flow_core/steps/parallel_split.rb
107
+ - app/models/flow_core/steps/redirection.rb
108
+ - app/models/flow_core/steps/task.rb
73
109
  - app/models/flow_core/task.rb
74
110
  - app/models/flow_core/token.rb
75
111
  - app/models/flow_core/transition.rb
@@ -77,7 +113,8 @@ files:
77
113
  - app/models/flow_core/transition_trigger.rb
78
114
  - app/models/flow_core/workflow.rb
79
115
  - config/routes.rb
80
- - db/migrate/20200130200532_create_flow_core_tables.rb
116
+ - db/migrate/20200130200532_create_workflow_tables.rb
117
+ - db/migrate/20200130200533_create_pipeline_tables.rb
81
118
  - lib/flow_core.rb
82
119
  - lib/flow_core/arc_guardable.rb
83
120
  - lib/flow_core/definition.rb
@@ -116,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
153
  - !ruby/object:Gem::Version
117
154
  version: '0'
118
155
  requirements: []
119
- rubygems_version: 3.0.8
156
+ rubygems_version: 3.1.4
120
157
  signing_key:
121
158
  specification_version: 4
122
159
  summary: A multi purpose, extendable, Workflow-net-based workflow engine for Rails