libis-workflow 2.0.beta.8 → 2.0.beta.9
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/base/run.rb +1 -1
- data/lib/libis/workflow/task.rb +18 -17
- data/lib/libis/workflow/tasks/analyzer.rb +10 -3
- data/lib/libis/workflow/version.rb +2 -2
- data/spec/task_spec.rb +1 -1
- data/spec/tasks/checksum_tester.rb +1 -1
- data/spec/tasks/collect_files.rb +3 -3
- data/spec/workflow_spec.rb +34 -40
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33d4917463c7c17ee5cd775275ccfe09c00a9360
|
4
|
+
data.tar.gz: f22d17de924236c69fefad0958257209d6cd94e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85837ac165f1e2d720ff6ca7d4386576b653eb592ff2bf721708253ce9549bc97df7a0d90003427c1e670a9bf66992f8151279bdc86c002f1021e65bc6135842
|
7
|
+
data.tar.gz: 59415cf0503c7821d3ee363760ba686114d1258bb142b5aa1cda68d03dcb8dab1a7076374fb9d1bc1bf75c99844424fe7f87543e03f0a4d2ebba4c2db34c260b
|
data/lib/libis/workflow/task.rb
CHANGED
@@ -15,8 +15,9 @@ module Libis
|
|
15
15
|
include ::Libis::Workflow::Base::Logger
|
16
16
|
include ::Libis::Tools::ParameterContainer
|
17
17
|
|
18
|
-
attr_accessor :parent, :name, :
|
18
|
+
attr_accessor :parent, :name, :workitem, :tasks
|
19
19
|
|
20
|
+
parameter quiet: false, description: 'Prevemt generating log output.'
|
20
21
|
parameter abort_on_error: false, description: 'Stop all tasks when an error occurs.'
|
21
22
|
parameter always_run: false, description: 'Run this task, even if the item failed a previous task.'
|
22
23
|
parameter subitems: false, description: 'Do not process the given item, but only the subitems.'
|
@@ -40,9 +41,9 @@ module Libis
|
|
40
41
|
|
41
42
|
check_item_type WorkItem, item
|
42
43
|
|
43
|
-
return if item.failed? unless
|
44
|
+
return if item.failed? unless parameter(:always_run)
|
44
45
|
|
45
|
-
if
|
46
|
+
if parameter(:subitems)
|
46
47
|
log_started item
|
47
48
|
run_subitems item
|
48
49
|
log_done(item) unless item.failed?
|
@@ -64,7 +65,7 @@ module Libis
|
|
64
65
|
|
65
66
|
pre_process item
|
66
67
|
process_item item
|
67
|
-
post_process
|
68
|
+
post_process workitem
|
68
69
|
|
69
70
|
rescue WorkflowError => e
|
70
71
|
error e.message
|
@@ -93,10 +94,11 @@ module Libis
|
|
93
94
|
def apply_options(opts)
|
94
95
|
o = opts[self.name] || opts[self.names.join('/')]
|
95
96
|
|
97
|
+
|
96
98
|
default_values.each do |name,_|
|
97
99
|
next unless o.key?(name)
|
98
100
|
parameter = get_parameter_definition name
|
99
|
-
self.
|
101
|
+
self.parameter(name, parameter.parse(o[name]))
|
100
102
|
end if o and o.is_a? Hash
|
101
103
|
|
102
104
|
self.tasks.each do |task|
|
@@ -123,8 +125,8 @@ module Libis
|
|
123
125
|
|
124
126
|
def process_item(item)
|
125
127
|
process item
|
126
|
-
run_subitems(
|
127
|
-
run_subtasks
|
128
|
+
run_subitems(workitem) if parameter(:recursive)
|
129
|
+
run_subtasks workitem
|
128
130
|
end
|
129
131
|
|
130
132
|
def process(item)
|
@@ -168,7 +170,7 @@ module Libis
|
|
168
170
|
run_item item
|
169
171
|
if item.failed?
|
170
172
|
failed += 1
|
171
|
-
if
|
173
|
+
if parameter(:abort_on_error)
|
172
174
|
error 'Aborting ...', parent_item
|
173
175
|
raise WorkflowAbort.new "Aborting: task #{name} failed on #{item}"
|
174
176
|
end
|
@@ -193,7 +195,7 @@ module Libis
|
|
193
195
|
debug 'Running subtask (%d/%d): %s', item, i+1, tasks.count, task.name
|
194
196
|
task.run item
|
195
197
|
if item.failed?
|
196
|
-
if task.
|
198
|
+
if task.parameter(:abort_on_error)
|
197
199
|
error 'Aborting ...'
|
198
200
|
raise WorkflowAbort.new "Aborting: task #{task.name} failed on #{item}"
|
199
201
|
end
|
@@ -204,12 +206,11 @@ module Libis
|
|
204
206
|
|
205
207
|
def configure(cfg)
|
206
208
|
self.name = cfg[:name] || (cfg[:class] || self.class).to_s.split('::').last
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
).symbolize_keys!
|
209
|
+
default_values.merge(
|
210
|
+
cfg[:options] || {}
|
211
|
+
).merge(
|
212
|
+
cfg.reject { |k, _| [:options].include? k.to_sym }
|
213
|
+
).symbolize_keys!.each { |k,v| parameter(k, v) }
|
213
214
|
end
|
214
215
|
|
215
216
|
def to_status(text)
|
@@ -232,13 +233,13 @@ module Libis
|
|
232
233
|
|
233
234
|
def subtasks(item = nil)
|
234
235
|
self.tasks.map do |task|
|
235
|
-
((item || self.workitem).failed? and not task.
|
236
|
+
((item || self.workitem).failed? and not task.parameter(:always_run)) ? nil : task
|
236
237
|
end.compact
|
237
238
|
end
|
238
239
|
|
239
240
|
def subitems(item = nil)
|
240
241
|
items = (item || workitem).items
|
241
|
-
return items if self.
|
242
|
+
return items if self.parameter(:always_run)
|
242
243
|
items.reject { |i| i.failed? }
|
243
244
|
end
|
244
245
|
|
@@ -8,14 +8,14 @@ module Libis
|
|
8
8
|
|
9
9
|
class Analyzer < Task
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
end
|
11
|
+
parameter quiet: true
|
12
|
+
parameter always_run: true
|
14
13
|
|
15
14
|
def run(item)
|
16
15
|
|
17
16
|
item.properties[:ingest_failed] = item.failed?
|
18
17
|
|
18
|
+
item.summary = {}
|
19
19
|
item.log_history.each do |log|
|
20
20
|
level = log[:severity]
|
21
21
|
item.summary[level] ||= 0
|
@@ -30,6 +30,13 @@ module Libis
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
rescue Exception => ex
|
34
|
+
|
35
|
+
puts 'Failed to analyze item: %s - %s' % [item.class, item.name]
|
36
|
+
puts 'Exception: %s' % ex.message
|
37
|
+
|
38
|
+
ensure
|
39
|
+
|
33
40
|
item.save
|
34
41
|
|
35
42
|
end
|
@@ -2,6 +2,6 @@
|
|
2
2
|
|
3
3
|
module Libis
|
4
4
|
module Workflow
|
5
|
-
VERSION = '2.0.beta.
|
5
|
+
VERSION = '2.0.beta.9' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
|
6
6
|
end
|
7
|
-
end
|
7
|
+
end
|
data/spec/task_spec.rb
CHANGED
@@ -13,7 +13,7 @@ class ChecksumTester < ::Libis::Workflow::Task
|
|
13
13
|
def process(item)
|
14
14
|
return unless item.is_a? TestFileItem
|
15
15
|
|
16
|
-
checksum_type =
|
16
|
+
checksum_type = parameter(:checksum_type)
|
17
17
|
|
18
18
|
if checksum_type.nil?
|
19
19
|
::Libis::Tools::Checksum::CHECKSUM_TYPES.each do |x|
|
data/spec/tasks/collect_files.rb
CHANGED
@@ -14,7 +14,7 @@ class CollectFiles < ::Libis::Workflow::Task
|
|
14
14
|
|
15
15
|
def process(item)
|
16
16
|
if item.is_a? TestRun
|
17
|
-
add_item(item,
|
17
|
+
add_item(item, parameter(:location))
|
18
18
|
elsif item.is_a? TestDirItem
|
19
19
|
collect_files(item, item.fullpath)
|
20
20
|
end
|
@@ -22,11 +22,11 @@ class CollectFiles < ::Libis::Workflow::Task
|
|
22
22
|
|
23
23
|
def collect_files(item, dir)
|
24
24
|
glob_string = dir
|
25
|
-
glob_string = File.join(glob_string, '**') if
|
25
|
+
glob_string = File.join(glob_string, '**') if parameter(:subdirs)
|
26
26
|
glob_string = File.join(glob_string, '*')
|
27
27
|
|
28
28
|
Dir.glob(glob_string).select do |x|
|
29
|
-
|
29
|
+
parameter(:selection) && !parameter(:selection).empty? ? x =~ Regexp.new(parameter(:selection)) : true
|
30
30
|
end.sort.each do |file|
|
31
31
|
next if %w'. ..'.include? file
|
32
32
|
add_item(item, file)
|
data/spec/workflow_spec.rb
CHANGED
@@ -4,24 +4,22 @@ require 'stringio'
|
|
4
4
|
|
5
5
|
describe 'TestWorkflow' do
|
6
6
|
|
7
|
-
|
7
|
+
let(:dirname) { File.absolute_path(File.join(File.dirname(__FILE__), 'items')) }
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
puts DIRNAME
|
12
|
-
|
13
|
-
@logoutput = StringIO.new
|
9
|
+
let(:logoutput) { StringIO.new }
|
14
10
|
|
11
|
+
let(:workflow) {
|
12
|
+
# noinspection RubyResolve
|
15
13
|
::Libis::Workflow.configure do |cfg|
|
16
14
|
cfg.itemdir = File.join(File.dirname(__FILE__), 'items')
|
17
15
|
cfg.taskdir = File.join(File.dirname(__FILE__), 'tasks')
|
18
16
|
cfg.workdir = File.join(File.dirname(__FILE__), 'work')
|
19
|
-
cfg.logger = Logger.new
|
17
|
+
cfg.logger = Logger.new logoutput
|
20
18
|
cfg.logger.level = Logger::DEBUG
|
21
19
|
end
|
22
20
|
|
23
|
-
|
24
|
-
|
21
|
+
workflow = ::Libis::Workflow::Workflow.new
|
22
|
+
workflow.configure(
|
25
23
|
name: 'TestWorkflow',
|
26
24
|
description: 'Workflow for testing',
|
27
25
|
tasks: [
|
@@ -42,33 +40,30 @@ describe 'TestWorkflow' do
|
|
42
40
|
checksum_type: {default: 'SHA1', propagate_to: 'ChecksumTester'}
|
43
41
|
}
|
44
42
|
)
|
43
|
+
workflow
|
44
|
+
}
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
46
|
+
let!(:run) {
|
47
|
+
workflow.run(dirname: dirname, checksum_type: 'SHA256')
|
48
|
+
}
|
51
49
|
|
52
50
|
it 'should contain three tasks' do
|
53
|
-
|
54
|
-
expect(
|
55
|
-
expect(
|
56
|
-
expect(@workflow.config[:tasks].last[:class]).to eq '::Libis::Workflow::Tasks::Analyzer'
|
57
|
-
|
51
|
+
expect(workflow.config[:tasks].size).to eq 3
|
52
|
+
expect(workflow.config[:tasks].first[:class]).to eq 'CollectFiles'
|
53
|
+
expect(workflow.config[:tasks].last[:class]).to eq '::Libis::Workflow::Tasks::Analyzer'
|
58
54
|
end
|
59
55
|
|
60
56
|
# noinspection RubyResolve
|
61
57
|
it 'should camelize the workitem name' do
|
58
|
+
expect(run.options[:dirname]).to eq dirname
|
59
|
+
expect(run.items.count).to eq 1
|
60
|
+
expect(run.items.first.class).to eq TestDirItem
|
61
|
+
expect(run.items.first.count).to eq 3
|
62
|
+
expect(run.items.first.first.class).to eq TestFileItem
|
62
63
|
|
63
|
-
expect(
|
64
|
-
expect(@run.items.count).to eq 1
|
65
|
-
expect(@run.items.first.class).to eq TestDirItem
|
66
|
-
expect(@run.items.first.count).to eq 3
|
67
|
-
expect(@run.items.first.first.class).to eq TestFileItem
|
68
|
-
|
69
|
-
expect(@run.items.first.name).to eq 'Items'
|
64
|
+
expect(run.items.first.name).to eq 'Items'
|
70
65
|
|
71
|
-
|
66
|
+
run.items.first.each_with_index do |x, i|
|
72
67
|
expect(x.name).to eq %w'TestDirItem.rb TestFileItem.rb TestRun.rb'[i]
|
73
68
|
end
|
74
69
|
end
|
@@ -126,19 +121,18 @@ DEBUG -- ProcessFiles - TestRun : 1 of 1 subitems passed
|
|
126
121
|
DEBUG -- ProcessFiles - TestRun : Completed
|
127
122
|
STR
|
128
123
|
sample_out = sample_out.lines.to_a
|
129
|
-
output =
|
124
|
+
output = logoutput.string.lines.to_a
|
130
125
|
|
131
|
-
puts output.join '\n'
|
132
126
|
expect(sample_out.count).to eq output.count
|
133
127
|
output.each_with_index do |o, i|
|
134
128
|
expect(o[/(?<=\] ).*/]).to eq sample_out[i].strip
|
135
129
|
end
|
136
130
|
|
137
|
-
expect(
|
138
|
-
expect(
|
139
|
-
expect(
|
140
|
-
expect(
|
141
|
-
expect(
|
131
|
+
expect(run.summary['DEBUG']).to eq 48
|
132
|
+
expect(run.log_history.count).to eq 8
|
133
|
+
expect(run.status_log.count).to eq 6
|
134
|
+
expect(run.items.first.log_history.count).to eq 22
|
135
|
+
expect(run.items.first.status_log.count).to eq 8
|
142
136
|
|
143
137
|
[
|
144
138
|
{tasklist: nil, text: :STARTED},
|
@@ -148,7 +142,7 @@ STR
|
|
148
142
|
{tasklist: %w'ProcessFiles', text: :Done},
|
149
143
|
{tasklist: nil, :text => :DONE},
|
150
144
|
].each_with_index do |h, i|
|
151
|
-
h.keys.each { |key| expect(
|
145
|
+
h.keys.each { |key| expect(run.status_log[i][key]).to eq h[key] }
|
152
146
|
end
|
153
147
|
|
154
148
|
[
|
@@ -161,7 +155,7 @@ STR
|
|
161
155
|
{tasklist: %w'ProcessFiles CamelizeName', text: :Done},
|
162
156
|
{tasklist: %w'ProcessFiles', text: :Done},
|
163
157
|
].each_with_index do |h, i|
|
164
|
-
h.keys.each { |key| expect(
|
158
|
+
h.keys.each { |key| expect(run.items.first.status_log[i][key]).to eq h[key] }
|
165
159
|
end
|
166
160
|
|
167
161
|
[
|
@@ -172,7 +166,7 @@ STR
|
|
172
166
|
{tasklist: %w'ProcessFiles CamelizeName', text: :Started},
|
173
167
|
{tasklist: %w'ProcessFiles CamelizeName', text: :Done},
|
174
168
|
].each_with_index do |h, i|
|
175
|
-
h.keys.each { |key| expect(
|
169
|
+
h.keys.each { |key| expect(run.items.first.first.status_log[i][key]).to eq h[key] }
|
176
170
|
end
|
177
171
|
|
178
172
|
[
|
@@ -185,7 +179,7 @@ STR
|
|
185
179
|
{severity: 'DEBUG', task: 'ProcessFiles', id: 0, message: '1 of 1 subitems passed'},
|
186
180
|
{severity: 'DEBUG', task: 'ProcessFiles', id: 0, message: 'Completed'},
|
187
181
|
].each_with_index do |h, i|
|
188
|
-
h.keys.each { |key| expect(
|
182
|
+
h.keys.each { |key| expect(run.log_history[i][key]).to eq h[key] }
|
189
183
|
end
|
190
184
|
|
191
185
|
[
|
@@ -212,7 +206,7 @@ STR
|
|
212
206
|
{severity: 'DEBUG', task: 'ProcessFiles/CamelizeName', id: 0, message: 'Completed'},
|
213
207
|
{severity: 'DEBUG', task: 'ProcessFiles', id: 0, message: 'Completed'},
|
214
208
|
].each_with_index do |h, i|
|
215
|
-
h.keys.each { |key| expect(
|
209
|
+
h.keys.each { |key| expect(run.items.first.log_history[i][key]).to eq h[key] }
|
216
210
|
end
|
217
211
|
|
218
212
|
[
|
@@ -223,7 +217,7 @@ STR
|
|
223
217
|
{severity: 'DEBUG', task: 'ProcessFiles/CamelizeName', id: 0, message: 'Started'},
|
224
218
|
{severity: 'DEBUG', task: 'ProcessFiles/CamelizeName', id: 0, message: 'Completed'},
|
225
219
|
].each_with_index do |h, i|
|
226
|
-
h.keys.each { |key| expect(
|
220
|
+
h.keys.each { |key| expect(run.items.first.first.log_history[i][key]).to eq h[key] }
|
227
221
|
end
|
228
222
|
|
229
223
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libis-workflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.beta.
|
4
|
+
version: 2.0.beta.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kris Dekeyser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|