libis-workflow-mongoid 2.0.beta.21 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/libis/workflow/mongoid/config.rb +2 -0
- data/lib/libis/workflow/mongoid/job.rb +25 -0
- data/lib/libis/workflow/mongoid/log_entry.rb +2 -1
- data/lib/libis/workflow/mongoid/run.rb +19 -0
- data/lib/libis/workflow/mongoid/version.rb +1 -1
- data/libis-workflow-mongoid.gemspec +1 -1
- data/spec/workflow_spec.rb +53 -52
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 475b4ffca7f1f3fb2db8a8657ffed71d15d7abcd
|
4
|
+
data.tar.gz: fcbef1f20aa86feea36d5a19fd7de4d8731b1673
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca8260f6aabe378a5f2f15e46bddb588b9bcd5da0a40339eccb62f27b04e37629e216f854f76a4dc5ddfce9b644731f76fca4e1f1f0c1119b48ff2f2f760aba7
|
7
|
+
data.tar.gz: eec596db0b15252f4ef48911b4c8d2b03ae49324812b660925440a2a21786e7c49fb71179b76e279232383626025fbcdf8ae02c025ba483ff3560b4ec35a02cb
|
@@ -18,6 +18,10 @@ module Libis
|
|
18
18
|
field :description, type: String
|
19
19
|
field :input, type: Hash, default: -> { Hash.new }
|
20
20
|
field :run_object, type: String
|
21
|
+
field :log_to_file, type: Boolean, default: false
|
22
|
+
field :log_level, type: String, default: 'DEBUG'
|
23
|
+
field :log_age, type: String, default: 'daily'
|
24
|
+
field :log_keep, type: Integer, default: 5
|
21
25
|
|
22
26
|
index({name: 1}, {unique: 1})
|
23
27
|
|
@@ -25,6 +29,27 @@ module Libis
|
|
25
29
|
|
26
30
|
belongs_to :workflow, polymorphic: true
|
27
31
|
|
32
|
+
def logger
|
33
|
+
return ::Libis::Workflow::Mongoid::Config.logger unless self.log_to_file
|
34
|
+
logger = ::Logging::Repository[self.name]
|
35
|
+
return logger if logger
|
36
|
+
unless ::Logging::Appenders[self.name]
|
37
|
+
::Logging::Appenders::RollingFile.new(
|
38
|
+
self.name,
|
39
|
+
filename: File.join(::Libis::Workflow::Mongoid::Config[:log_dir], "#{self.name}{.%Y%m%d}.log"),
|
40
|
+
layout: Config.get_log_formatter,
|
41
|
+
truncate: true,
|
42
|
+
age: self.log_age,
|
43
|
+
keep: self.log_keep,
|
44
|
+
roll_by: 'date',
|
45
|
+
level: self.log_level
|
46
|
+
)
|
47
|
+
end
|
48
|
+
logger = Config.logger(self.name, self.name)
|
49
|
+
logger.additive = false
|
50
|
+
logger
|
51
|
+
end
|
52
|
+
|
28
53
|
# def create_run_object
|
29
54
|
# # noinspection RubyResolve
|
30
55
|
# self.runs.build
|
@@ -14,10 +14,11 @@ module Libis
|
|
14
14
|
store_in collection: 'log'
|
15
15
|
|
16
16
|
field :severity, type: String
|
17
|
-
field :task, type: String, default: '
|
17
|
+
field :task, type: String, default: ''
|
18
18
|
field :code, type: Integer
|
19
19
|
field :message, type: String
|
20
20
|
field :status, type: String
|
21
|
+
field :run_id
|
21
22
|
|
22
23
|
belongs_to :logger, polymorphic: true
|
23
24
|
|
@@ -17,6 +17,7 @@ module Libis
|
|
17
17
|
store_in collection: 'workflow_runs'
|
18
18
|
|
19
19
|
field :start_date, type: Time, default: -> { Time.now }
|
20
|
+
field :log_to_file, type: Boolean, default: false
|
20
21
|
|
21
22
|
set_callback(:destroy, :before) do |document|
|
22
23
|
wd = document.work_dir
|
@@ -26,6 +27,7 @@ module Libis
|
|
26
27
|
index start_date: 1
|
27
28
|
|
28
29
|
belongs_to :job, polymorphic: true
|
30
|
+
embeds_one :log_config, as: :log_configurator
|
29
31
|
|
30
32
|
def run
|
31
33
|
self.tasks = []
|
@@ -34,6 +36,23 @@ module Libis
|
|
34
36
|
super
|
35
37
|
end
|
36
38
|
|
39
|
+
def logger
|
40
|
+
return ::Libis::Workflow::Mongoid::Config.logger unless self.log_to_file
|
41
|
+
logger = ::Logging::Repository[self.name]
|
42
|
+
return logger if logger
|
43
|
+
unless ::Logging::Appenders[self.name]
|
44
|
+
::Logging::Appenders::File.new(
|
45
|
+
self.name,
|
46
|
+
filename: File.join(::Libis::Workflow::Mongoid::Config[:log_dir], "#{self.name}.log"),
|
47
|
+
layout: Config.get_log_formatter,
|
48
|
+
level: self.log_level
|
49
|
+
)
|
50
|
+
end
|
51
|
+
logger = Config.logger(self.name, self.name)
|
52
|
+
logger.additive = false
|
53
|
+
logger
|
54
|
+
end
|
55
|
+
|
37
56
|
end
|
38
57
|
|
39
58
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Libis
|
4
4
|
module Workflow
|
5
5
|
module Mongoid
|
6
|
-
VERSION = '2.0.
|
6
|
+
VERSION = '2.0.1' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
data/spec/workflow_spec.rb
CHANGED
@@ -14,19 +14,18 @@ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
|
14
14
|
|
15
15
|
describe 'TestWorkflow' do
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
dirname = File.absolute_path(File.join(File.dirname(__FILE__), 'items'))
|
18
|
+
|
19
|
+
before :each do
|
20
20
|
|
21
21
|
# noinspection RubyResolve
|
22
22
|
::Libis::Workflow::Mongoid.configure do |cfg|
|
23
23
|
cfg.itemdir = File.join(File.dirname(__FILE__), 'items')
|
24
24
|
cfg.taskdir = File.join(File.dirname(__FILE__), 'tasks')
|
25
25
|
cfg.workdir = File.join(File.dirname(__FILE__), 'work')
|
26
|
-
cfg.logger = Logger.new logoutput
|
27
|
-
cfg.set_log_formatter
|
28
|
-
cfg.logger.level = Logger::DEBUG
|
29
26
|
cfg.database_connect 'mongoid.yml', :test
|
27
|
+
cfg.logger.appenders =
|
28
|
+
::Logging::Appenders.string_io('StringIO', layout: ::Libis::Tools::Config.get_log_formatter)
|
30
29
|
end
|
31
30
|
|
32
31
|
TestWorkflow.create_indexes
|
@@ -34,8 +33,11 @@ describe 'TestWorkflow' do
|
|
34
33
|
TestFileItem.create_indexes
|
35
34
|
TestDirItem.create_indexes
|
36
35
|
|
37
|
-
|
38
|
-
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:workflow) {
|
39
|
+
wf = TestWorkflow.find_or_initialize_by(name: 'TestWorkflow')
|
40
|
+
wf.configure(
|
39
41
|
name: 'TestWorkflow',
|
40
42
|
description: 'Workflow for testing',
|
41
43
|
tasks: [
|
@@ -44,8 +46,8 @@ describe 'TestWorkflow' do
|
|
44
46
|
name: 'ProcessFiles',
|
45
47
|
subitems: true,
|
46
48
|
tasks: [
|
47
|
-
{class: 'ChecksumTester',
|
48
|
-
{class: 'CamelizeName',
|
49
|
+
{class: 'ChecksumTester', recursive: true},
|
50
|
+
{class: 'CamelizeName', recursive: true}
|
49
51
|
]
|
50
52
|
}
|
51
53
|
],
|
@@ -54,29 +56,28 @@ describe 'TestWorkflow' do
|
|
54
56
|
checksum_type: {default: 'SHA1', propagate_to: 'ProcessFiles/ChecksumTester'}
|
55
57
|
}
|
56
58
|
)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
59
|
+
wf.save
|
60
|
+
wf
|
61
|
+
}
|
62
|
+
let(:job) {
|
63
|
+
job = TestJob.find_or_initialize_by(name: 'TestJob')
|
64
|
+
job.configure(
|
65
|
+
name: 'TestJob',
|
66
|
+
description: 'Job for testing',
|
67
|
+
workflow: workflow,
|
68
|
+
run_object: 'TestRun',
|
69
|
+
input: {dirname: dirname, checksum_type: 'SHA256'},
|
66
70
|
)
|
67
71
|
|
68
72
|
# noinspection RubyResolve
|
69
|
-
|
70
|
-
|
71
|
-
|
73
|
+
job.runs.each { |run| run.destroy! }
|
74
|
+
job.save
|
75
|
+
job
|
76
|
+
}
|
72
77
|
|
73
|
-
|
78
|
+
let(:run) { job.execute }
|
74
79
|
|
75
|
-
|
76
|
-
def logoutput; @logoutput; end
|
77
|
-
def workflow; @workflow; end
|
78
|
-
def job; @job; end
|
79
|
-
def run; @run; end
|
80
|
+
let(:logoutput) { ::Libis::Tools::Config.logger.appenders.first.sio }
|
80
81
|
|
81
82
|
it 'should contain three tasks' do
|
82
83
|
|
@@ -88,7 +89,6 @@ describe 'TestWorkflow' do
|
|
88
89
|
|
89
90
|
it 'should camelize the workitem name' do
|
90
91
|
|
91
|
-
puts run.options
|
92
92
|
expect(run.options['CollectFiles']['location']).to eq dirname
|
93
93
|
|
94
94
|
expect(run.items.size).to eq 1
|
@@ -120,29 +120,29 @@ describe 'TestWorkflow' do
|
|
120
120
|
expect(item.summary['DEBUG']).to eq 15
|
121
121
|
|
122
122
|
sample_out = <<STR
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
123
|
+
CollectFiles - TestRun : Processing subitem (1/1): items
|
124
|
+
CollectFiles - items : Processing subitem (1/4): test_dir_item.rb
|
125
|
+
CollectFiles - items : Processing subitem (2/4): test_file_item.rb
|
126
|
+
CollectFiles - items : Processing subitem (3/4): test_item.rb
|
127
|
+
CollectFiles - items : Processing subitem (4/4): test_run.rb
|
128
|
+
CollectFiles - items : 4 of 4 subitems passed
|
129
|
+
CollectFiles - TestRun : 1 of 1 subitems passed
|
130
|
+
ProcessFiles - TestRun : Running subtask (1/2): ChecksumTester
|
131
|
+
ProcessFiles/ChecksumTester - TestRun : Processing subitem (1/1): items
|
132
|
+
ProcessFiles/ChecksumTester - items : Processing subitem (1/4): test_dir_item.rb
|
133
|
+
ProcessFiles/ChecksumTester - items : Processing subitem (2/4): test_file_item.rb
|
134
|
+
ProcessFiles/ChecksumTester - items : Processing subitem (3/4): test_item.rb
|
135
|
+
ProcessFiles/ChecksumTester - items : Processing subitem (4/4): test_run.rb
|
136
|
+
ProcessFiles/ChecksumTester - items : 4 of 4 subitems passed
|
137
|
+
ProcessFiles/ChecksumTester - TestRun : 1 of 1 subitems passed
|
138
|
+
ProcessFiles - TestRun : Running subtask (2/2): CamelizeName
|
139
|
+
ProcessFiles/CamelizeName - TestRun : Processing subitem (1/1): items
|
140
|
+
ProcessFiles/CamelizeName - Items : Processing subitem (1/4): test_dir_item.rb
|
141
|
+
ProcessFiles/CamelizeName - Items : Processing subitem (2/4): test_file_item.rb
|
142
|
+
ProcessFiles/CamelizeName - Items : Processing subitem (3/4): test_item.rb
|
143
|
+
ProcessFiles/CamelizeName - Items : Processing subitem (4/4): test_run.rb
|
144
|
+
ProcessFiles/CamelizeName - Items : 4 of 4 subitems passed
|
145
|
+
ProcessFiles/CamelizeName - TestRun : 1 of 1 subitems passed
|
146
146
|
STR
|
147
147
|
sample_out = sample_out.lines.to_a
|
148
148
|
output = logoutput.string.lines
|
@@ -177,6 +177,7 @@ STR
|
|
177
177
|
|
178
178
|
# noinspection RubyResolve
|
179
179
|
it 'find run' do
|
180
|
+
run
|
180
181
|
my_job = TestJob.first
|
181
182
|
expect(my_job).to eq job
|
182
183
|
expect(my_job.runs.all.count).to eq 1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libis-workflow-mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kris Dekeyser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libis-workflow
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.0
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.0
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mongoid
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,9 +154,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
154
|
version: '0'
|
155
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- - "
|
157
|
+
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
159
|
+
version: '0'
|
160
160
|
requirements: []
|
161
161
|
rubyforge_project:
|
162
162
|
rubygems_version: 2.4.8
|
@@ -178,3 +178,4 @@ test_files:
|
|
178
178
|
- spec/test_job.rb
|
179
179
|
- spec/test_workflow.rb
|
180
180
|
- spec/workflow_spec.rb
|
181
|
+
has_rdoc:
|