libis-workflow 2.0.24 → 2.0.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -1
- data/.gitignore +36 -36
- data/.travis.yml +32 -32
- data/Gemfile +4 -4
- data/LICENSE +20 -20
- data/README.md +380 -380
- data/Rakefile +6 -6
- data/lib/libis/exceptions.rb +6 -6
- data/lib/libis/workflow.rb +41 -41
- data/lib/libis/workflow/action.rb +24 -24
- data/lib/libis/workflow/base/dir_item.rb +13 -13
- data/lib/libis/workflow/base/file_item.rb +80 -80
- data/lib/libis/workflow/base/job.rb +83 -83
- data/lib/libis/workflow/base/logging.rb +66 -66
- data/lib/libis/workflow/base/run.rb +95 -95
- data/lib/libis/workflow/base/work_item.rb +173 -173
- data/lib/libis/workflow/base/workflow.rb +149 -149
- data/lib/libis/workflow/config.rb +22 -22
- data/lib/libis/workflow/dir_item.rb +10 -10
- data/lib/libis/workflow/file_item.rb +15 -15
- data/lib/libis/workflow/job.rb +28 -28
- data/lib/libis/workflow/message_registry.rb +30 -30
- data/lib/libis/workflow/run.rb +34 -34
- data/lib/libis/workflow/status.rb +133 -133
- data/lib/libis/workflow/task.rb +316 -316
- data/lib/libis/workflow/task_group.rb +71 -71
- data/lib/libis/workflow/task_runner.rb +34 -34
- data/lib/libis/workflow/version.rb +5 -5
- data/lib/libis/workflow/work_item.rb +37 -37
- data/lib/libis/workflow/worker.rb +42 -42
- data/lib/libis/workflow/workflow.rb +20 -20
- data/libis-workflow.gemspec +38 -38
- data/spec/items.rb +2 -2
- data/spec/items/test_dir_item.rb +13 -13
- data/spec/items/test_file_item.rb +16 -16
- data/spec/items/test_run.rb +8 -8
- data/spec/spec_helper.rb +8 -8
- data/spec/task_spec.rb +15 -15
- data/spec/tasks/camelize_name.rb +12 -12
- data/spec/tasks/checksum_tester.rb +32 -32
- data/spec/tasks/collect_files.rb +47 -47
- data/spec/workflow_spec.rb +154 -154
- metadata +3 -3
data/spec/items.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
require_relative 'items/test_dir_item'
|
2
|
-
require_relative 'items/test_file_item'
|
1
|
+
require_relative 'items/test_dir_item'
|
2
|
+
require_relative 'items/test_file_item'
|
3
3
|
require_relative 'items/test_run'
|
data/spec/items/test_dir_item.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require 'libis/workflow/dir_item'
|
2
|
-
|
3
|
-
class TestDirItem < ::Libis::Workflow::DirItem
|
4
|
-
|
5
|
-
def name=(dir)
|
6
|
-
raise RuntimeError, "'#{dir}' is not a directory" unless File.directory? dir
|
7
|
-
super dir
|
8
|
-
end
|
9
|
-
|
10
|
-
def name
|
11
|
-
self.properties[:name] || super
|
12
|
-
end
|
13
|
-
|
1
|
+
require 'libis/workflow/dir_item'
|
2
|
+
|
3
|
+
class TestDirItem < ::Libis::Workflow::DirItem
|
4
|
+
|
5
|
+
def name=(dir)
|
6
|
+
raise RuntimeError, "'#{dir}' is not a directory" unless File.directory? dir
|
7
|
+
super dir
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
self.properties[:name] || super
|
12
|
+
end
|
13
|
+
|
14
14
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
require 'libis/tools/checksum'
|
2
|
-
|
3
|
-
require 'libis/workflow/file_item'
|
4
|
-
|
5
|
-
class TestFileItem < ::Libis::Workflow::FileItem
|
6
|
-
|
7
|
-
def filename=(file)
|
8
|
-
raise RuntimeError, "'#{file}' is not a file" unless File.file? file
|
9
|
-
set_checksum :SHA256, ::Libis::Tools::Checksum.hexdigest(file, :SHA256)
|
10
|
-
super file
|
11
|
-
end
|
12
|
-
|
13
|
-
def name
|
14
|
-
self.properties[:name] || super
|
15
|
-
end
|
16
|
-
|
1
|
+
require 'libis/tools/checksum'
|
2
|
+
|
3
|
+
require 'libis/workflow/file_item'
|
4
|
+
|
5
|
+
class TestFileItem < ::Libis::Workflow::FileItem
|
6
|
+
|
7
|
+
def filename=(file)
|
8
|
+
raise RuntimeError, "'#{file}' is not a file" unless File.file? file
|
9
|
+
set_checksum :SHA256, ::Libis::Tools::Checksum.hexdigest(file, :SHA256)
|
10
|
+
super file
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
self.properties[:name] || super
|
15
|
+
end
|
16
|
+
|
17
17
|
end
|
data/spec/items/test_run.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require 'libis/workflow/run'
|
2
|
-
|
3
|
-
require_relative 'test_dir_item'
|
4
|
-
|
5
|
-
class TestRun < ::Libis::Workflow::Run
|
6
|
-
|
7
|
-
def name; 'TestRun'; end
|
8
|
-
|
1
|
+
require 'libis/workflow/run'
|
2
|
+
|
3
|
+
require_relative 'test_dir_item'
|
4
|
+
|
5
|
+
class TestRun < ::Libis::Workflow::Run
|
6
|
+
|
7
|
+
def name; 'TestRun'; end
|
8
|
+
|
9
9
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'coveralls'
|
2
|
-
Coveralls.wear!
|
3
|
-
|
4
|
-
require 'bundler/setup'
|
5
|
-
Bundler.setup
|
6
|
-
|
7
|
-
require 'rspec'
|
8
|
-
require 'libis-workflow'
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
Bundler.setup
|
6
|
+
|
7
|
+
require 'rspec'
|
8
|
+
require 'libis-workflow'
|
data/spec/task_spec.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
|
3
|
-
require 'libis/workflow/task'
|
4
|
-
|
5
|
-
describe 'Task' do
|
6
|
-
|
7
|
-
it 'should create a default task' do
|
8
|
-
|
9
|
-
task = ::Libis::Workflow::Task.new nil
|
10
|
-
|
11
|
-
expect(task.parent).to eq nil
|
12
|
-
expect(task.name).to eq 'Task'
|
13
|
-
|
14
|
-
end
|
15
|
-
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
require 'libis/workflow/task'
|
4
|
+
|
5
|
+
describe 'Task' do
|
6
|
+
|
7
|
+
it 'should create a default task' do
|
8
|
+
|
9
|
+
task = ::Libis::Workflow::Task.new nil
|
10
|
+
|
11
|
+
expect(task.parent).to eq nil
|
12
|
+
expect(task.name).to eq 'Task'
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
16
|
end
|
data/spec/tasks/camelize_name.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require 'backports/rails/string'
|
2
|
-
|
3
|
-
require 'libis/workflow'
|
4
|
-
|
5
|
-
class CamelizeName < ::Libis::Workflow::Task
|
6
|
-
|
7
|
-
def process(item)
|
8
|
-
return unless (item.is_a?(TestFileItem) || item.is_a?(TestDirItem))
|
9
|
-
item.properties[:name] = item.name.camelize
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
1
|
+
require 'backports/rails/string'
|
2
|
+
|
3
|
+
require 'libis/workflow'
|
4
|
+
|
5
|
+
class CamelizeName < ::Libis::Workflow::Task
|
6
|
+
|
7
|
+
def process(item)
|
8
|
+
return unless (item.is_a?(TestFileItem) || item.is_a?(TestDirItem))
|
9
|
+
item.properties[:name] = item.name.camelize
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -1,32 +1,32 @@
|
|
1
|
-
require 'libis/tools/checksum'
|
2
|
-
|
3
|
-
require 'libis/exceptions'
|
4
|
-
require 'libis/workflow'
|
5
|
-
|
6
|
-
class ChecksumTester < ::Libis::Workflow::Task
|
7
|
-
|
8
|
-
parameter checksum_type: nil,
|
9
|
-
description: 'Checksum type to use.',
|
10
|
-
constraint: ::Libis::Tools::Checksum::CHECKSUM_TYPES.map {|x| x.to_s}
|
11
|
-
|
12
|
-
def process(item)
|
13
|
-
return unless item.is_a? TestFileItem
|
14
|
-
|
15
|
-
checksum_type = parameter(:checksum_type)
|
16
|
-
|
17
|
-
if checksum_type.nil?
|
18
|
-
::Libis::Tools::Checksum::CHECKSUM_TYPES.each do |x|
|
19
|
-
test_checksum(item, x) if item.checksum(x)
|
20
|
-
end
|
21
|
-
else
|
22
|
-
test_checksum(item, checksum_type)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_checksum(item, checksum_type)
|
27
|
-
checksum = ::Libis::Tools::Checksum.hexdigest(item.fullpath, checksum_type.to_sym)
|
28
|
-
return if item.checksum(checksum_type) == checksum
|
29
|
-
raise ::Libis::WorkflowError, "Checksum test #{checksum_type} failed for #{item.filepath}"
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
1
|
+
require 'libis/tools/checksum'
|
2
|
+
|
3
|
+
require 'libis/exceptions'
|
4
|
+
require 'libis/workflow'
|
5
|
+
|
6
|
+
class ChecksumTester < ::Libis::Workflow::Task
|
7
|
+
|
8
|
+
parameter checksum_type: nil,
|
9
|
+
description: 'Checksum type to use.',
|
10
|
+
constraint: ::Libis::Tools::Checksum::CHECKSUM_TYPES.map {|x| x.to_s}
|
11
|
+
|
12
|
+
def process(item)
|
13
|
+
return unless item.is_a? TestFileItem
|
14
|
+
|
15
|
+
checksum_type = parameter(:checksum_type)
|
16
|
+
|
17
|
+
if checksum_type.nil?
|
18
|
+
::Libis::Tools::Checksum::CHECKSUM_TYPES.each do |x|
|
19
|
+
test_checksum(item, x) if item.checksum(x)
|
20
|
+
end
|
21
|
+
else
|
22
|
+
test_checksum(item, checksum_type)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_checksum(item, checksum_type)
|
27
|
+
checksum = ::Libis::Tools::Checksum.hexdigest(item.fullpath, checksum_type.to_sym)
|
28
|
+
return if item.checksum(checksum_type) == checksum
|
29
|
+
raise ::Libis::WorkflowError, "Checksum test #{checksum_type} failed for #{item.filepath}"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/spec/tasks/collect_files.rb
CHANGED
@@ -1,47 +1,47 @@
|
|
1
|
-
require 'libis/exceptions'
|
2
|
-
|
3
|
-
require_relative '../items'
|
4
|
-
|
5
|
-
class CollectFiles < ::Libis::Workflow::Task
|
6
|
-
|
7
|
-
parameter location: '.',
|
8
|
-
description: 'Dir location to start scanning for files.'
|
9
|
-
parameter subdirs: false,
|
10
|
-
description: 'Look for files in subdirs too.'
|
11
|
-
parameter selection: nil,
|
12
|
-
description: 'Only select files that match the given regular expression. Ignored if empty.'
|
13
|
-
|
14
|
-
def process(item)
|
15
|
-
if item.is_a? TestRun
|
16
|
-
add_item(item, parameter(:location))
|
17
|
-
elsif item.is_a? TestDirItem
|
18
|
-
collect_files(item, item.fullpath)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def collect_files(item, dir)
|
23
|
-
glob_string = dir
|
24
|
-
glob_string = File.join(glob_string, '**') if parameter(:subdirs)
|
25
|
-
glob_string = File.join(glob_string, '*')
|
26
|
-
|
27
|
-
Dir.glob(glob_string).select do |x|
|
28
|
-
parameter(:selection) && !parameter(:selection).empty? ? x =~ Regexp.new(parameter(:selection)) : true
|
29
|
-
end.sort.each do |file|
|
30
|
-
next if %w'. ..'.include? file
|
31
|
-
add_item(item, file)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def add_item(item, file)
|
36
|
-
child = if File.file?(file)
|
37
|
-
TestFileItem.new
|
38
|
-
elsif File.directory?(file)
|
39
|
-
TestDirItem.new
|
40
|
-
else
|
41
|
-
Item.new
|
42
|
-
end
|
43
|
-
child.filename = file
|
44
|
-
item << child
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
1
|
+
require 'libis/exceptions'
|
2
|
+
|
3
|
+
require_relative '../items'
|
4
|
+
|
5
|
+
class CollectFiles < ::Libis::Workflow::Task
|
6
|
+
|
7
|
+
parameter location: '.',
|
8
|
+
description: 'Dir location to start scanning for files.'
|
9
|
+
parameter subdirs: false,
|
10
|
+
description: 'Look for files in subdirs too.'
|
11
|
+
parameter selection: nil,
|
12
|
+
description: 'Only select files that match the given regular expression. Ignored if empty.'
|
13
|
+
|
14
|
+
def process(item)
|
15
|
+
if item.is_a? TestRun
|
16
|
+
add_item(item, parameter(:location))
|
17
|
+
elsif item.is_a? TestDirItem
|
18
|
+
collect_files(item, item.fullpath)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def collect_files(item, dir)
|
23
|
+
glob_string = dir
|
24
|
+
glob_string = File.join(glob_string, '**') if parameter(:subdirs)
|
25
|
+
glob_string = File.join(glob_string, '*')
|
26
|
+
|
27
|
+
Dir.glob(glob_string).select do |x|
|
28
|
+
parameter(:selection) && !parameter(:selection).empty? ? x =~ Regexp.new(parameter(:selection)) : true
|
29
|
+
end.sort.each do |file|
|
30
|
+
next if %w'. ..'.include? file
|
31
|
+
add_item(item, file)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_item(item, file)
|
36
|
+
child = if File.file?(file)
|
37
|
+
TestFileItem.new
|
38
|
+
elsif File.directory?(file)
|
39
|
+
TestDirItem.new
|
40
|
+
else
|
41
|
+
Item.new
|
42
|
+
end
|
43
|
+
child.filename = file
|
44
|
+
item << child
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/spec/workflow_spec.rb
CHANGED
@@ -1,155 +1,155 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
|
3
|
-
require 'stringio'
|
4
|
-
|
5
|
-
describe 'TestWorkflow' do
|
6
|
-
|
7
|
-
basedir = File.absolute_path File.join(File.dirname(__FILE__))
|
8
|
-
dirname = File.join(basedir, 'items')
|
9
|
-
|
10
|
-
before :each do
|
11
|
-
|
12
|
-
# noinspection RubyResolve
|
13
|
-
::Libis::Workflow.configure do |cfg|
|
14
|
-
cfg.itemdir = dirname
|
15
|
-
cfg.taskdir = File.join(basedir, 'tasks')
|
16
|
-
cfg.workdir = File.join(basedir, 'work')
|
17
|
-
cfg.logger.appenders =
|
18
|
-
::Logging::Appenders.string_io('StringIO', layout: ::Libis::Tools::Config.get_log_formatter)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:logoutput) { ::Libis::Workflow::Config.logger.appenders.first.sio }
|
23
|
-
|
24
|
-
let(:workflow) {
|
25
|
-
workflow = ::Libis::Workflow::Workflow.new
|
26
|
-
workflow.configure(
|
27
|
-
'name' => 'TestWorkflow',
|
28
|
-
'description' => 'Workflow for testing',
|
29
|
-
'tasks' => [
|
30
|
-
{'class' => 'CollectFiles', 'recursive' => true},
|
31
|
-
{
|
32
|
-
'name' => 'ProcessFiles', 'recursive' => false,
|
33
|
-
'tasks' => [
|
34
|
-
{'class' => 'ChecksumTester', 'recursive' => true},
|
35
|
-
{'class' => 'CamelizeName', 'recursive' => true}
|
36
|
-
]
|
37
|
-
}
|
38
|
-
],
|
39
|
-
'input' => {
|
40
|
-
'dirname' => {'default' => '.', 'propagate_to' => 'CollectFiles#location'},
|
41
|
-
'checksum_type' => {'default' => 'SHA1', 'propagate_to' => 'ChecksumTester'}
|
42
|
-
}
|
43
|
-
)
|
44
|
-
workflow
|
45
|
-
}
|
46
|
-
|
47
|
-
let(:job) {
|
48
|
-
job = ::Libis::Workflow::Job.new
|
49
|
-
job.configure(
|
50
|
-
'name' => 'TestJob',
|
51
|
-
'description' => 'Job for testing',
|
52
|
-
'workflow' => workflow,
|
53
|
-
'run_object' => 'TestRun',
|
54
|
-
'input' => {'dirname' => dirname, 'checksum_type' => 'SHA256'},
|
55
|
-
)
|
56
|
-
job
|
57
|
-
}
|
58
|
-
|
59
|
-
it 'should contain three tasks' do
|
60
|
-
expect(workflow.config['tasks'].size).to eq 2
|
61
|
-
expect(workflow.config['tasks'].first['class']).to eq 'CollectFiles'
|
62
|
-
expect(workflow.config['tasks'].last['name']).to eq 'ProcessFiles'
|
63
|
-
end
|
64
|
-
|
65
|
-
# noinspection RubyResolve
|
66
|
-
it 'should camelize the workitem name' do
|
67
|
-
run = job.execute
|
68
|
-
expect(run.options['CollectFiles']['location']).to eq dirname
|
69
|
-
expect(run.size).to eq 1
|
70
|
-
expect(run.items.size).to eq 1
|
71
|
-
expect(run.items.first.class).to eq TestDirItem
|
72
|
-
expect(run.items.first.size).to eq 3
|
73
|
-
expect(run.items.first.items.size).to eq 3
|
74
|
-
expect(run.items.first.first.class).to eq TestFileItem
|
75
|
-
|
76
|
-
expect(run.items.first.name).to eq 'Items'
|
77
|
-
|
78
|
-
run.items.first.each_with_index do |x, i|
|
79
|
-
expect(x.name).to eq %w'TestDirItem.rb TestFileItem.rb TestRun.rb'[i]
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'should return expected debug output' do
|
84
|
-
|
85
|
-
sample_out = <<STR
|
86
|
-
INFO -- Run - TestRun : Ingest run started.
|
87
|
-
INFO -- Run - TestRun : Running subtask (1/2): CollectFiles
|
88
|
-
DEBUG -- CollectFiles - TestRun : Processing subitem (1/1): items
|
89
|
-
DEBUG -- CollectFiles - items : Processing subitem (1/3): test_dir_item.rb
|
90
|
-
DEBUG -- CollectFiles - items : Processing subitem (2/3): test_file_item.rb
|
91
|
-
DEBUG -- CollectFiles - items : Processing subitem (3/3): test_run.rb
|
92
|
-
DEBUG -- CollectFiles - items : 3 of 3 subitems passed
|
93
|
-
DEBUG -- CollectFiles - TestRun : 1 of 1 subitems passed
|
94
|
-
INFO -- Run - TestRun : Running subtask (2/2): ProcessFiles
|
95
|
-
INFO -- ProcessFiles - TestRun : Running subtask (1/2): ChecksumTester
|
96
|
-
DEBUG -- ProcessFiles/ChecksumTester - TestRun : Processing subitem (1/1): items
|
97
|
-
DEBUG -- ProcessFiles/ChecksumTester - items : Processing subitem (1/3): test_dir_item.rb
|
98
|
-
DEBUG -- ProcessFiles/ChecksumTester - items : Processing subitem (2/3): test_file_item.rb
|
99
|
-
DEBUG -- ProcessFiles/ChecksumTester - items : Processing subitem (3/3): test_run.rb
|
100
|
-
DEBUG -- ProcessFiles/ChecksumTester - items : 3 of 3 subitems passed
|
101
|
-
DEBUG -- ProcessFiles/ChecksumTester - TestRun : 1 of 1 subitems passed
|
102
|
-
INFO -- ProcessFiles - TestRun : Running subtask (2/2): CamelizeName
|
103
|
-
DEBUG -- ProcessFiles/CamelizeName - TestRun : Processing subitem (1/1): items
|
104
|
-
DEBUG -- ProcessFiles/CamelizeName - Items : Processing subitem (1/3): test_dir_item.rb
|
105
|
-
DEBUG -- ProcessFiles/CamelizeName - Items : Processing subitem (2/3): test_file_item.rb
|
106
|
-
DEBUG -- ProcessFiles/CamelizeName - Items : Processing subitem (3/3): test_run.rb
|
107
|
-
DEBUG -- ProcessFiles/CamelizeName - Items : 3 of 3 subitems passed
|
108
|
-
DEBUG -- ProcessFiles/CamelizeName - TestRun : 1 of 1 subitems passed
|
109
|
-
INFO -- ProcessFiles - TestRun : Done
|
110
|
-
INFO -- Run - TestRun : Done
|
111
|
-
STR
|
112
|
-
sample_out = sample_out.lines.to_a
|
113
|
-
|
114
|
-
run = job.execute
|
115
|
-
output = logoutput.string.lines.to_a
|
116
|
-
|
117
|
-
# puts output
|
118
|
-
|
119
|
-
expect(output.size).to eq sample_out.size
|
120
|
-
output.each_with_index do |o, i|
|
121
|
-
expect(o[/(?<=\] ).*/].strip).to eq sample_out[i].strip
|
122
|
-
end
|
123
|
-
|
124
|
-
expect(run.status_log.size).to eq 5
|
125
|
-
expect(run.items.first.status_log.size).to eq 3
|
126
|
-
|
127
|
-
[
|
128
|
-
{task: 'Run', status: :DONE, progress: 2, max: 2},
|
129
|
-
{task: 'CollectFiles', status: :DONE, progress: 1, max: 1},
|
130
|
-
{task: 'ProcessFiles', status: :DONE, progress: 2, max: 2},
|
131
|
-
{task: 'ProcessFiles/ChecksumTester', status: :DONE, progress: 1, max: 1},
|
132
|
-
{task: 'ProcessFiles/CamelizeName', status: :DONE, progress: 1, max: 1},
|
133
|
-
].each_with_index do |h, i|
|
134
|
-
h.keys.each { |key| expect(run.status_log[i][key.to_s]).to eq h[key] }
|
135
|
-
end
|
136
|
-
|
137
|
-
[
|
138
|
-
{task: 'CollectFiles', status: :DONE, progress: 3, max: 3},
|
139
|
-
{task: 'ProcessFiles/ChecksumTester', status: :DONE, progress: 3, max: 3},
|
140
|
-
{task: 'ProcessFiles/CamelizeName', status: :DONE, progress: 3, max: 3},
|
141
|
-
].each_with_index do |h, i|
|
142
|
-
h.keys.each { |key| expect(run.items.first.status_log[i][key.to_s]).to eq h[key] }
|
143
|
-
end
|
144
|
-
|
145
|
-
[
|
146
|
-
{task: 'CollectFiles', status: :DONE, progress: nil, max: nil},
|
147
|
-
{task: 'ProcessFiles/ChecksumTester', status: :DONE, progress: nil, max: nil},
|
148
|
-
{task: 'ProcessFiles/CamelizeName', status: :DONE, progress: nil, max: nil},
|
149
|
-
].each_with_index do |h, i|
|
150
|
-
h.keys.each { |key| expect(run.items.first.first.status_log[i][key.to_s]).to eq h[key] }
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
154
|
-
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
describe 'TestWorkflow' do
|
6
|
+
|
7
|
+
basedir = File.absolute_path File.join(File.dirname(__FILE__))
|
8
|
+
dirname = File.join(basedir, 'items')
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
|
12
|
+
# noinspection RubyResolve
|
13
|
+
::Libis::Workflow.configure do |cfg|
|
14
|
+
cfg.itemdir = dirname
|
15
|
+
cfg.taskdir = File.join(basedir, 'tasks')
|
16
|
+
cfg.workdir = File.join(basedir, 'work')
|
17
|
+
cfg.logger.appenders =
|
18
|
+
::Logging::Appenders.string_io('StringIO', layout: ::Libis::Tools::Config.get_log_formatter)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:logoutput) { ::Libis::Workflow::Config.logger.appenders.first.sio }
|
23
|
+
|
24
|
+
let(:workflow) {
|
25
|
+
workflow = ::Libis::Workflow::Workflow.new
|
26
|
+
workflow.configure(
|
27
|
+
'name' => 'TestWorkflow',
|
28
|
+
'description' => 'Workflow for testing',
|
29
|
+
'tasks' => [
|
30
|
+
{'class' => 'CollectFiles', 'recursive' => true},
|
31
|
+
{
|
32
|
+
'name' => 'ProcessFiles', 'recursive' => false,
|
33
|
+
'tasks' => [
|
34
|
+
{'class' => 'ChecksumTester', 'recursive' => true},
|
35
|
+
{'class' => 'CamelizeName', 'recursive' => true}
|
36
|
+
]
|
37
|
+
}
|
38
|
+
],
|
39
|
+
'input' => {
|
40
|
+
'dirname' => {'default' => '.', 'propagate_to' => 'CollectFiles#location'},
|
41
|
+
'checksum_type' => {'default' => 'SHA1', 'propagate_to' => 'ChecksumTester'}
|
42
|
+
}
|
43
|
+
)
|
44
|
+
workflow
|
45
|
+
}
|
46
|
+
|
47
|
+
let(:job) {
|
48
|
+
job = ::Libis::Workflow::Job.new
|
49
|
+
job.configure(
|
50
|
+
'name' => 'TestJob',
|
51
|
+
'description' => 'Job for testing',
|
52
|
+
'workflow' => workflow,
|
53
|
+
'run_object' => 'TestRun',
|
54
|
+
'input' => {'dirname' => dirname, 'checksum_type' => 'SHA256'},
|
55
|
+
)
|
56
|
+
job
|
57
|
+
}
|
58
|
+
|
59
|
+
it 'should contain three tasks' do
|
60
|
+
expect(workflow.config['tasks'].size).to eq 2
|
61
|
+
expect(workflow.config['tasks'].first['class']).to eq 'CollectFiles'
|
62
|
+
expect(workflow.config['tasks'].last['name']).to eq 'ProcessFiles'
|
63
|
+
end
|
64
|
+
|
65
|
+
# noinspection RubyResolve
|
66
|
+
it 'should camelize the workitem name' do
|
67
|
+
run = job.execute
|
68
|
+
expect(run.options['CollectFiles']['location']).to eq dirname
|
69
|
+
expect(run.size).to eq 1
|
70
|
+
expect(run.items.size).to eq 1
|
71
|
+
expect(run.items.first.class).to eq TestDirItem
|
72
|
+
expect(run.items.first.size).to eq 3
|
73
|
+
expect(run.items.first.items.size).to eq 3
|
74
|
+
expect(run.items.first.first.class).to eq TestFileItem
|
75
|
+
|
76
|
+
expect(run.items.first.name).to eq 'Items'
|
77
|
+
|
78
|
+
run.items.first.each_with_index do |x, i|
|
79
|
+
expect(x.name).to eq %w'TestDirItem.rb TestFileItem.rb TestRun.rb'[i]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should return expected debug output' do
|
84
|
+
|
85
|
+
sample_out = <<STR
|
86
|
+
INFO -- Run - TestRun : Ingest run started.
|
87
|
+
INFO -- Run - TestRun : Running subtask (1/2): CollectFiles
|
88
|
+
DEBUG -- CollectFiles - TestRun : Processing subitem (1/1): items
|
89
|
+
DEBUG -- CollectFiles - items : Processing subitem (1/3): test_dir_item.rb
|
90
|
+
DEBUG -- CollectFiles - items : Processing subitem (2/3): test_file_item.rb
|
91
|
+
DEBUG -- CollectFiles - items : Processing subitem (3/3): test_run.rb
|
92
|
+
DEBUG -- CollectFiles - items : 3 of 3 subitems passed
|
93
|
+
DEBUG -- CollectFiles - TestRun : 1 of 1 subitems passed
|
94
|
+
INFO -- Run - TestRun : Running subtask (2/2): ProcessFiles
|
95
|
+
INFO -- ProcessFiles - TestRun : Running subtask (1/2): ChecksumTester
|
96
|
+
DEBUG -- ProcessFiles/ChecksumTester - TestRun : Processing subitem (1/1): items
|
97
|
+
DEBUG -- ProcessFiles/ChecksumTester - items : Processing subitem (1/3): test_dir_item.rb
|
98
|
+
DEBUG -- ProcessFiles/ChecksumTester - items : Processing subitem (2/3): test_file_item.rb
|
99
|
+
DEBUG -- ProcessFiles/ChecksumTester - items : Processing subitem (3/3): test_run.rb
|
100
|
+
DEBUG -- ProcessFiles/ChecksumTester - items : 3 of 3 subitems passed
|
101
|
+
DEBUG -- ProcessFiles/ChecksumTester - TestRun : 1 of 1 subitems passed
|
102
|
+
INFO -- ProcessFiles - TestRun : Running subtask (2/2): CamelizeName
|
103
|
+
DEBUG -- ProcessFiles/CamelizeName - TestRun : Processing subitem (1/1): items
|
104
|
+
DEBUG -- ProcessFiles/CamelizeName - Items : Processing subitem (1/3): test_dir_item.rb
|
105
|
+
DEBUG -- ProcessFiles/CamelizeName - Items : Processing subitem (2/3): test_file_item.rb
|
106
|
+
DEBUG -- ProcessFiles/CamelizeName - Items : Processing subitem (3/3): test_run.rb
|
107
|
+
DEBUG -- ProcessFiles/CamelizeName - Items : 3 of 3 subitems passed
|
108
|
+
DEBUG -- ProcessFiles/CamelizeName - TestRun : 1 of 1 subitems passed
|
109
|
+
INFO -- ProcessFiles - TestRun : Done
|
110
|
+
INFO -- Run - TestRun : Done
|
111
|
+
STR
|
112
|
+
sample_out = sample_out.lines.to_a
|
113
|
+
|
114
|
+
run = job.execute
|
115
|
+
output = logoutput.string.lines.to_a
|
116
|
+
|
117
|
+
# puts output
|
118
|
+
|
119
|
+
expect(output.size).to eq sample_out.size
|
120
|
+
output.each_with_index do |o, i|
|
121
|
+
expect(o[/(?<=\] ).*/].strip).to eq sample_out[i].strip
|
122
|
+
end
|
123
|
+
|
124
|
+
expect(run.status_log.size).to eq 5
|
125
|
+
expect(run.items.first.status_log.size).to eq 3
|
126
|
+
|
127
|
+
[
|
128
|
+
{task: 'Run', status: :DONE, progress: 2, max: 2},
|
129
|
+
{task: 'CollectFiles', status: :DONE, progress: 1, max: 1},
|
130
|
+
{task: 'ProcessFiles', status: :DONE, progress: 2, max: 2},
|
131
|
+
{task: 'ProcessFiles/ChecksumTester', status: :DONE, progress: 1, max: 1},
|
132
|
+
{task: 'ProcessFiles/CamelizeName', status: :DONE, progress: 1, max: 1},
|
133
|
+
].each_with_index do |h, i|
|
134
|
+
h.keys.each { |key| expect(run.status_log[i][key.to_s]).to eq h[key] }
|
135
|
+
end
|
136
|
+
|
137
|
+
[
|
138
|
+
{task: 'CollectFiles', status: :DONE, progress: 3, max: 3},
|
139
|
+
{task: 'ProcessFiles/ChecksumTester', status: :DONE, progress: 3, max: 3},
|
140
|
+
{task: 'ProcessFiles/CamelizeName', status: :DONE, progress: 3, max: 3},
|
141
|
+
].each_with_index do |h, i|
|
142
|
+
h.keys.each { |key| expect(run.items.first.status_log[i][key.to_s]).to eq h[key] }
|
143
|
+
end
|
144
|
+
|
145
|
+
[
|
146
|
+
{task: 'CollectFiles', status: :DONE, progress: nil, max: nil},
|
147
|
+
{task: 'ProcessFiles/ChecksumTester', status: :DONE, progress: nil, max: nil},
|
148
|
+
{task: 'ProcessFiles/CamelizeName', status: :DONE, progress: nil, max: nil},
|
149
|
+
].each_with_index do |h, i|
|
150
|
+
h.keys.each { |key| expect(run.items.first.first.status_log[i][key.to_s]).to eq h[key] }
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
155
|
end
|