libis-workflow-mongoid 2.0.beta.14 → 2.0.beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/libis/workflow/mongoid/job.rb +16 -26
- data/lib/libis/workflow/mongoid/run.rb +12 -43
- data/lib/libis/workflow/mongoid/version.rb +1 -1
- data/lib/libis/workflow/mongoid/work_item.rb +5 -26
- data/lib/libis/workflow/mongoid/work_item_base.rb +9 -23
- data/lib/libis/workflow/mongoid/workflow.rb +16 -25
- data/lib/libis/workflow/mongoid.rb +2 -2
- data/mongoid.yml +1 -1
- data/spec/items/test_dir_item.rb +1 -0
- data/spec/items/test_file_item.rb +1 -0
- data/spec/items/test_item.rb +1 -3
- data/spec/items/test_run.rb +1 -5
- data/spec/test_job.rb +1 -4
- data/spec/test_workflow.rb +1 -3
- data/spec/workflow_spec.rb +8 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 257d09f473547c6a373ff1040d3ab93bd2a3c7f0
|
4
|
+
data.tar.gz: 57a636a4ecb6dd41c817b95ecc8b9d41df58d437
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68011bc0fe042fff0434fabbae544e3a0b0f8177e0f67c6230458fc46847d9d2c8b99acaaeecdafa279d2981c87a83a000eadbcdf04f1b0db3a3126ca3ee74ea
|
7
|
+
data.tar.gz: fb282a3b8f7cc371b6e338664541acc19353b575b753479ef3df05b019081841660fb6c7971612a7d55c92543cce180f16e5a51f872eb8145799e56d43db14d9
|
@@ -7,41 +7,31 @@ module Libis
|
|
7
7
|
module Workflow
|
8
8
|
module Mongoid
|
9
9
|
|
10
|
-
|
10
|
+
class Job
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
include ::Libis::Workflow::Base::Job
|
15
|
-
include ::Libis::Workflow::Mongoid::Base
|
12
|
+
include ::Libis::Workflow::Base::Job
|
13
|
+
include ::Libis::Workflow::Mongoid::Base
|
16
14
|
|
17
|
-
|
15
|
+
store_in collection: 'workflow_jobs'
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
field :name, type: String
|
18
|
+
field :description, type: String
|
19
|
+
field :input, type: Hash, default: -> { Hash.new }
|
20
|
+
field :run_object, type: String
|
23
21
|
|
24
|
-
|
22
|
+
index({name: 1}, {unique: 1})
|
25
23
|
|
26
|
-
|
27
|
-
has_many :runs, inverse_of: :job, class_name: run_klass.to_s,
|
28
|
-
dependent: :destroy, autosave: true, order: :c_at.asc
|
29
|
-
end
|
24
|
+
has_many :runs, as: :job, dependent: :destroy, autosave: true, order: :c_at.asc
|
30
25
|
|
31
|
-
|
32
|
-
belongs_to :workflow, inverse_of: :jobs, class_name: workflow_klass.to_s
|
33
|
-
end
|
26
|
+
belongs_to :workflow, polymorphic: true
|
34
27
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
28
|
+
# def create_run_object
|
29
|
+
# # noinspection RubyResolve
|
30
|
+
# self.runs.build
|
31
|
+
# end
|
43
32
|
|
44
33
|
end
|
34
|
+
|
45
35
|
end
|
46
36
|
end
|
47
37
|
end
|
@@ -8,36 +8,24 @@ module Libis
|
|
8
8
|
module Workflow
|
9
9
|
module Mongoid
|
10
10
|
|
11
|
-
|
12
|
-
# extend ActiveSupport::Concern
|
11
|
+
class Run
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
include ::Libis::Workflow::Mongoid::WorkItemBase
|
13
|
+
include ::Libis::Workflow::Base::Run
|
14
|
+
include ::Libis::Workflow::Mongoid::WorkItemBase
|
15
|
+
# extend ActiveSupport::Concern
|
18
16
|
|
19
|
-
|
17
|
+
store_in collection: 'workflow_runs'
|
20
18
|
|
21
|
-
|
19
|
+
field :start_date, type: Time, default: -> { Time.now }
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
21
|
+
set_callback(:destroy, :before) do |document|
|
22
|
+
wd = document.work_dir
|
23
|
+
FileUtils.rmtree wd if wd && !wd.blank? && Dir.exist?(wd)
|
24
|
+
end
|
28
25
|
|
29
|
-
|
26
|
+
index start_date: 1
|
30
27
|
|
31
|
-
|
32
|
-
belongs_to :job, inverse_of: :runs, class_name: job_klass.to_s
|
33
|
-
end
|
34
|
-
|
35
|
-
def klass.item_class(item_klass)
|
36
|
-
has_many :items, inverse_of: :run, class_name: item_klass.to_s,
|
37
|
-
dependent: :destroy, autosave: true, order: :c_at.asc
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
28
|
+
belongs_to :job, polymorphic: true
|
41
29
|
|
42
30
|
def run
|
43
31
|
self.tasks = []
|
@@ -46,25 +34,6 @@ module Libis
|
|
46
34
|
super
|
47
35
|
end
|
48
36
|
|
49
|
-
# Add a child work item
|
50
|
-
#
|
51
|
-
# @param [Libis::Workflow::Mongoid::WorkItem] item to be added to the child list :items
|
52
|
-
def add_item(item)
|
53
|
-
# noinspection RubyResolve
|
54
|
-
item.run = self
|
55
|
-
super
|
56
|
-
end
|
57
|
-
|
58
|
-
alias_method :<<, :add_item
|
59
|
-
|
60
|
-
def parent
|
61
|
-
nil
|
62
|
-
end
|
63
|
-
|
64
|
-
def parent=(_)
|
65
|
-
nil
|
66
|
-
end
|
67
|
-
|
68
37
|
end
|
69
38
|
|
70
39
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Libis
|
4
4
|
module Workflow
|
5
5
|
module Mongoid
|
6
|
-
VERSION = '2.0.beta.
|
6
|
+
VERSION = '2.0.beta.15' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -1,36 +1,15 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'libis
|
2
|
+
require 'libis-workflow'
|
3
|
+
require_relative 'dynamic'
|
3
4
|
|
4
5
|
module Libis
|
5
6
|
module Workflow
|
6
7
|
module Mongoid
|
7
8
|
|
8
|
-
|
9
|
+
class WorkItem
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
include Libis::Workflow::Mongoid::WorkItemBase
|
13
|
-
|
14
|
-
store_in collection: 'workflow_items'
|
15
|
-
|
16
|
-
has_many :items, inverse_of: :parent, class_name: klass.to_s,
|
17
|
-
dependent: :destroy, autosave: true, order: :_id.asc
|
18
|
-
belongs_to :parent, inverse_of: :items, class_name: klass.to_s
|
19
|
-
|
20
|
-
set_callback(:destroy, :before) do |document|
|
21
|
-
document.items.each { |item| item.destroy! }
|
22
|
-
end
|
23
|
-
|
24
|
-
def klass.run_class(run_klass)
|
25
|
-
belongs_to :run, inverse_of: :items, class_name: run_klass.to_s
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def get_parent
|
32
|
-
self.parent || self.run
|
33
|
-
end
|
11
|
+
include Libis::Workflow::Base::WorkItem
|
12
|
+
include Libis::Workflow::Mongoid::WorkItemBase
|
34
13
|
|
35
14
|
end
|
36
15
|
|
@@ -10,17 +10,17 @@ module Libis
|
|
10
10
|
|
11
11
|
class Options
|
12
12
|
include Libis::Workflow::Mongoid::Dynamic
|
13
|
-
embedded_in :work_item, class_name: Libis::Workflow::Mongoid::
|
13
|
+
embedded_in :work_item, class_name: 'Libis::Workflow::Mongoid::WorkItem'
|
14
14
|
end
|
15
15
|
|
16
16
|
class Properties
|
17
17
|
include Libis::Workflow::Mongoid::Dynamic
|
18
|
-
embedded_in :work_item, class_name: Libis::Workflow::Mongoid::
|
18
|
+
embedded_in :work_item, class_name: 'Libis::Workflow::Mongoid::WorkItem'
|
19
19
|
end
|
20
20
|
|
21
21
|
class Summary
|
22
22
|
include Libis::Workflow::Mongoid::Dynamic
|
23
|
-
embedded_in :work_item, class_name: Libis::Workflow::Mongoid::
|
23
|
+
embedded_in :work_item, class_name: 'Libis::Workflow::Mongoid::WorkItem'
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.included(klass)
|
@@ -28,6 +28,8 @@ module Libis
|
|
28
28
|
include Libis::Workflow::Base::WorkItem
|
29
29
|
include Libis::Workflow::Mongoid::Base
|
30
30
|
|
31
|
+
store_in collection: 'workflow_items'
|
32
|
+
|
31
33
|
embeds_one :options, class_name: Libis::Workflow::Mongoid::WorkItemBase::Options.to_s
|
32
34
|
embeds_one :properties, class_name: Libis::Workflow::Mongoid::WorkItemBase::Properties.to_s
|
33
35
|
embeds_one :summary, class_name: Libis::Workflow::Mongoid::WorkItemBase::Summary.to_s
|
@@ -43,10 +45,10 @@ module Libis
|
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
has_many :items, as: :parent, class_name: Libis::Workflow::Mongoid::WorkItem.to_s,
|
49
|
+
dependent: :destroy, autosave: true, order: :c_at.asc
|
50
|
+
|
51
|
+
belongs_to :parent, polymorphic: true
|
50
52
|
|
51
53
|
set_callback(:destroy, :before) do |document|
|
52
54
|
# noinspection RubyResolve
|
@@ -60,24 +62,8 @@ module Libis
|
|
60
62
|
end
|
61
63
|
|
62
64
|
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
def each
|
67
|
-
self.items.each { |item| yield item }
|
68
65
|
end
|
69
66
|
|
70
|
-
def get_items
|
71
|
-
self.items.to_a
|
72
|
-
end
|
73
|
-
|
74
|
-
def item_count
|
75
|
-
self.items.count
|
76
|
-
end
|
77
|
-
|
78
|
-
alias_method :count, :item_count
|
79
|
-
alias_method :size, :item_count
|
80
|
-
|
81
67
|
def log_history
|
82
68
|
# noinspection RubyResolve
|
83
69
|
self.logs.log_history.all || []
|
@@ -9,37 +9,28 @@ module Libis
|
|
9
9
|
module Workflow
|
10
10
|
module Mongoid
|
11
11
|
|
12
|
-
|
12
|
+
class Workflow
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
include ::Libis::Workflow::Base::Workflow
|
17
|
-
include ::Libis::Workflow::Mongoid::Base
|
14
|
+
include ::Libis::Workflow::Base::Workflow
|
15
|
+
include ::Libis::Workflow::Mongoid::Base
|
18
16
|
|
19
|
-
|
17
|
+
store_in collection: 'workflow_definitions'
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
field :name, type: String
|
20
|
+
field :description, type: String
|
21
|
+
field :config, type: Hash, default: -> { Hash.new }
|
24
22
|
|
25
|
-
|
23
|
+
index({name: 1}, {unique: 1})
|
26
24
|
|
27
|
-
|
28
|
-
has_many :jobs, inverse_of: :workflow, class_name: job_klass.to_s,
|
29
|
-
dependent: :destroy, autosave: true, order: :c_at.asc
|
30
|
-
end
|
31
|
-
|
32
|
-
def klass.load(file_or_hash)
|
33
|
-
config = Libis::Tools::ConfigFile.new
|
34
|
-
config << file_or_hash
|
35
|
-
return nil if config.empty?
|
36
|
-
workflow = self.new
|
37
|
-
workflow.configure(config.to_hash.key_strings_to_symbols(recursive: true))
|
38
|
-
workflow
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
25
|
+
has_many :jobs, as: :workflow, dependent: :destroy, autosave: true, order: :c_at.asc
|
42
26
|
|
27
|
+
def self.load(file_or_hash)
|
28
|
+
config = Libis::Tools::ConfigFile.new
|
29
|
+
config << file_or_hash
|
30
|
+
return nil if config.empty?
|
31
|
+
workflow = self.new
|
32
|
+
workflow.configure(config.to_hash.key_strings_to_symbols(recursive: true))
|
33
|
+
workflow
|
43
34
|
end
|
44
35
|
|
45
36
|
end
|
@@ -12,9 +12,9 @@ module Libis
|
|
12
12
|
autoload :Config, 'libis/workflow/mongoid/config'
|
13
13
|
autoload :LogEntry, 'libis/workflow/mongoid/log_entry'
|
14
14
|
autoload :Job, 'libis/workflow/mongoid/job'
|
15
|
-
autoload :Run, 'libis/workflow/mongoid/run'
|
16
|
-
autoload :WorkItem, 'libis/workflow/mongoid/work_item'
|
17
15
|
autoload :WorkItemBase, 'libis/workflow/mongoid/work_item_base'
|
16
|
+
autoload :WorkItem, 'libis/workflow/mongoid/work_item'
|
17
|
+
autoload :Run, 'libis/workflow/mongoid/run'
|
18
18
|
autoload :Worker, 'libis/workflow/mongoid/worker'
|
19
19
|
autoload :Workflow, 'libis/workflow/mongoid/workflow'
|
20
20
|
|
data/mongoid.yml
CHANGED
@@ -110,7 +110,7 @@ test:
|
|
110
110
|
|
111
111
|
# Preload all models in development, needed when models use
|
112
112
|
# inheritance. (default: false)
|
113
|
-
|
113
|
+
preload_models: true
|
114
114
|
|
115
115
|
# Raise an error when performing a #find and the document is not found.
|
116
116
|
# (default: true)
|
data/spec/items/test_dir_item.rb
CHANGED
data/spec/items/test_item.rb
CHANGED
data/spec/items/test_run.rb
CHANGED
data/spec/test_job.rb
CHANGED
data/spec/test_workflow.rb
CHANGED
data/spec/workflow_spec.rb
CHANGED
@@ -90,25 +90,19 @@ describe 'TestWorkflow' do
|
|
90
90
|
|
91
91
|
expect(run.options['CollectFiles'][:location]).to eq dirname
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
print_item(i, indent + 1)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
print_item(run)
|
100
|
-
|
93
|
+
expect(run.items.size).to eq 1
|
94
|
+
expect(run.items.count).to eq 1
|
95
|
+
expect(run.size).to eq 1
|
101
96
|
expect(run.count).to eq 1
|
97
|
+
expect(run.items.first.class).to eq TestDirItem
|
102
98
|
expect(run.first.class).to eq TestDirItem
|
99
|
+
expect(run.first.items.size).to eq 4
|
100
|
+
expect(run.first.items.count).to eq 4
|
101
|
+
expect(run.first.size).to eq 4
|
103
102
|
expect(run.first.count).to eq 4
|
103
|
+
expect(run.first.items.first.class).to eq TestFileItem
|
104
104
|
expect(run.first.first.class).to eq TestFileItem
|
105
105
|
|
106
|
-
# the following tests do not work on Travis. Tried for days to find out why, but I give up.
|
107
|
-
# expect(run.get_items.count).to eq 1
|
108
|
-
# expect(run.get_items.first.class).to eq TestDirItem
|
109
|
-
# expect(run.get_items.first.count).to eq 4
|
110
|
-
# expect(run.get_items.first.get_items.first.class).to eq TestFileItem
|
111
|
-
|
112
106
|
run.items.first.each_with_index do |x, i|
|
113
107
|
expect(x.name).to eq %w'TestDirItem.rb TestFileItem.rb TestItem.rb TestRun.rb'[i]
|
114
108
|
end
|