libis-workflow-mongoid 2.0.beta.7.1 → 2.0.beta.8
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/base.rb +4 -1
- data/lib/libis/workflow/mongoid/sequence.rb +74 -0
- data/lib/libis/workflow/mongoid/version.rb +2 -2
- data/lib/libis/workflow/mongoid/workflow.rb +1 -1
- data/lib/libis/workflow/mongoid.rb +2 -0
- data/spec/tasks/checksum_tester.rb +1 -1
- data/spec/tasks/collect_files.rb +6 -4
- data/spec/workflow_spec.rb +63 -58
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfa94b307591f08d69fad83f79bf8807c56037fd
|
4
|
+
data.tar.gz: d484aa41a3da41c6d6c282b073231b17faa6948d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70bf6048529e08dc5cf543788af85d9a8fcea6d36c90ad16d5a6b41c11644abbd38de87557a8d7ae3ae4aa8826de16298d6197811a92a065e7fb302cf2ac506f
|
7
|
+
data.tar.gz: 8cde72beefe397820d0eed41c70218469f93523712ab12c8beff27b89c685105279229ae2f71af635a7023b8589f59a34954314b2c0b707f0dd82f7411633d2e
|
@@ -2,6 +2,7 @@
|
|
2
2
|
require 'mongoid'
|
3
3
|
require 'mongoid/document'
|
4
4
|
require 'mongoid_indifferent_access'
|
5
|
+
require_relative 'sequence'
|
5
6
|
|
6
7
|
module Libis
|
7
8
|
module Workflow
|
@@ -12,8 +13,10 @@ module Libis
|
|
12
13
|
def self.included(klass)
|
13
14
|
klass.class_eval do
|
14
15
|
include ::Mongoid::Document
|
15
|
-
include ::Mongoid::Timestamps
|
16
16
|
include ::Mongoid::Extensions::Hash::IndifferentAccess
|
17
|
+
include ::Libis::Workflow::Mongoid::Sequence
|
18
|
+
field :_id, type: Integer
|
19
|
+
sequence :_id
|
17
20
|
index created_at: 1
|
18
21
|
end
|
19
22
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#require 'mongoid/fields/validators/macro'
|
2
|
+
|
3
|
+
module Libis
|
4
|
+
module Workflow
|
5
|
+
module Mongoid
|
6
|
+
|
7
|
+
# Include this module to add automatic sequence feature (also works for _id field, so SQL-Like autoincrement primary key can easily be simulated)
|
8
|
+
# usage:
|
9
|
+
# class KlassName
|
10
|
+
# include Mongoid::Document
|
11
|
+
# include LIBIS::Mongoid::Sequence
|
12
|
+
# ...
|
13
|
+
# field :number, :type=>Integer
|
14
|
+
# sequence :number
|
15
|
+
# ...
|
16
|
+
# Note: only tested on Mongoid 3.x and 4.x
|
17
|
+
module Sequence
|
18
|
+
extend ActiveSupport::Concern
|
19
|
+
|
20
|
+
#noinspection ALL
|
21
|
+
module ClassMethods
|
22
|
+
|
23
|
+
def sequence(_field, prefix = nil)
|
24
|
+
# REPLACE FIELD DEFAULT VALUE
|
25
|
+
_field = _field.to_s
|
26
|
+
options = fields[_field].options.merge(
|
27
|
+
default: lambda {
|
28
|
+
self.class.set_from_sequence(_field, prefix)
|
29
|
+
},
|
30
|
+
pre_processed: false
|
31
|
+
)
|
32
|
+
(options.keys - ::Mongoid::Fields::Validators::Macro::OPTIONS).each { |key| options.delete key }
|
33
|
+
field(_field, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_from_sequence(_field, prefix)
|
37
|
+
# Increase the sequence value and also avoids conflicts
|
38
|
+
catch(:value) do
|
39
|
+
value = nil
|
40
|
+
begin
|
41
|
+
value = seq_upsert(counter_id(_field), {'$inc' => {'value' => 1}}).send('[]', 'value')
|
42
|
+
value = "#{prefix.is_a?(Proc) ? instance_eval(prefix.call) : prefix}_#{value}" if prefix
|
43
|
+
end until self.where(_field => value).count == 0
|
44
|
+
throw :value, value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def reset_sequence(_field, value = 0)
|
49
|
+
seq_upsert(counter_id(_field), {'$set' => {'value' => value}})
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
def counter_id(_field)
|
55
|
+
#"#{self.name.underscore}##{_field}"
|
56
|
+
"#{collection_name.to_s}##{_field}"
|
57
|
+
end
|
58
|
+
|
59
|
+
def sequences
|
60
|
+
# mongo_session["#{self.collection_name.to_s}__seq"]
|
61
|
+
mongo_session["__sequences__"]
|
62
|
+
end
|
63
|
+
|
64
|
+
def seq_upsert(counter_id, change)
|
65
|
+
sequences.where(_id: counter_id).modify(change, upsert: true, new: true)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
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.8' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
|
7
7
|
end
|
8
8
|
end
|
9
|
-
end
|
9
|
+
end
|
@@ -14,7 +14,7 @@ module Libis
|
|
14
14
|
include ::Libis::Workflow::Base::Workflow
|
15
15
|
include ::Libis::Workflow::Mongoid::Base
|
16
16
|
|
17
|
-
store_in collection: '
|
17
|
+
store_in collection: 'workflow_definitions'
|
18
18
|
|
19
19
|
field :name, type: String
|
20
20
|
field :description, type: String
|
@@ -14,7 +14,7 @@ class ChecksumTester < ::Libis::Workflow::Task
|
|
14
14
|
def process(item)
|
15
15
|
return unless item.is_a? TestFileItem
|
16
16
|
|
17
|
-
checksum_type =
|
17
|
+
checksum_type = parameter(:checksum_type)
|
18
18
|
|
19
19
|
if checksum_type.nil?
|
20
20
|
::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)
|
@@ -39,8 +39,10 @@ class CollectFiles < ::Libis::Workflow::Task
|
|
39
39
|
elsif File.directory?(file)
|
40
40
|
TestDirItem.new
|
41
41
|
else
|
42
|
-
|
42
|
+
error 'Bad file type encountered: %s', file
|
43
|
+
nil
|
43
44
|
end
|
45
|
+
return unless child
|
44
46
|
child.filename = file
|
45
47
|
item << child
|
46
48
|
end
|
data/spec/workflow_spec.rb
CHANGED
@@ -9,21 +9,21 @@ require_relative 'spec_helper'
|
|
9
9
|
require_relative 'test_workflow'
|
10
10
|
require_relative 'items'
|
11
11
|
|
12
|
-
|
12
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
13
13
|
|
14
14
|
describe 'TestWorkflow' do
|
15
15
|
|
16
|
-
|
17
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
16
|
+
let(:dirname) { File.absolute_path(File.join(File.dirname(__FILE__), 'items')) }
|
18
17
|
|
18
|
+
let(:logoutput) { StringIO.new }
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
let(:workflow) {
|
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
|
26
|
+
cfg.logger = Logger.new logoutput
|
27
27
|
cfg.set_log_formatter
|
28
28
|
cfg.logger.level = Logger::DEBUG
|
29
29
|
cfg.database_connect 'mongoid.yml', :test
|
@@ -36,8 +36,8 @@ describe 'TestWorkflow' do
|
|
36
36
|
|
37
37
|
TestWorkflow.each { |wf| wf.destroy }
|
38
38
|
|
39
|
-
|
40
|
-
|
39
|
+
workflow = TestWorkflow.new
|
40
|
+
workflow.configure(
|
41
41
|
name: 'TestWorkflow',
|
42
42
|
description: 'Workflow for testing',
|
43
43
|
tasks: [
|
@@ -56,36 +56,44 @@ describe 'TestWorkflow' do
|
|
56
56
|
checksum_type: {default: 'SHA1', propagate_to: 'ProcessFiles/ChecksumTester'}
|
57
57
|
}
|
58
58
|
)
|
59
|
-
|
59
|
+
workflow.save
|
60
|
+
workflow
|
61
|
+
}
|
60
62
|
|
63
|
+
let(:run) {
|
61
64
|
# noinspection RubyStringKeysInHashInspection
|
62
|
-
|
63
|
-
|
64
|
-
end
|
65
|
+
workflow.run(dirname: dirname, checksum_type: 'SHA256')
|
66
|
+
}
|
65
67
|
|
66
68
|
it 'should contain three tasks' do
|
67
69
|
|
68
|
-
expect(
|
69
|
-
expect(
|
70
|
-
expect(
|
70
|
+
expect(workflow.config[:tasks].size).to eq 3
|
71
|
+
expect(workflow.config[:tasks].first[:class]).to eq 'CollectFiles'
|
72
|
+
expect(workflow.config[:tasks].last[:class]).to eq '::Libis::Workflow::Tasks::Analyzer'
|
71
73
|
|
72
74
|
end
|
73
75
|
|
74
76
|
it 'should camelize the workitem name' do
|
75
77
|
|
76
|
-
expect(
|
77
|
-
expect(
|
78
|
-
expect(
|
79
|
-
expect(
|
80
|
-
expect(
|
78
|
+
expect(run.options[:dirname]).to eq dirname
|
79
|
+
expect(run.items.count).to eq 1
|
80
|
+
expect(run.items.first.class).to eq TestDirItem
|
81
|
+
expect(run.items.first.count).to eq 4
|
82
|
+
expect(run.items.first.first.class).to eq TestFileItem
|
81
83
|
|
82
|
-
|
84
|
+
run.items.first.each_with_index do |x, i|
|
83
85
|
expect(x.name).to eq %w'TestDirItem.rb TestFileItem.rb TestItem.rb TestRun.rb'[i]
|
84
86
|
end
|
85
87
|
end
|
86
88
|
|
87
89
|
it 'should return expected debug output' do
|
88
90
|
|
91
|
+
expect(run.summary['DEBUG']).to eq 57
|
92
|
+
expect(run.log_history.count).to eq 8
|
93
|
+
expect(run.status_log.count).to eq 6
|
94
|
+
expect(run.items.first.log_history.count).to eq 25
|
95
|
+
expect(run.items.first.status_log.count).to eq 8
|
96
|
+
|
89
97
|
sample_out = <<STR
|
90
98
|
DEBUG -- CollectFiles - TestRun : Started
|
91
99
|
DEBUG -- CollectFiles - TestRun : Processing subitem (1/1): items
|
@@ -146,60 +154,57 @@ DEBUG -- ProcessFiles - TestRun : 1 of 1 subitems passed
|
|
146
154
|
DEBUG -- ProcessFiles - TestRun : Completed
|
147
155
|
STR
|
148
156
|
sample_out = sample_out.lines.to_a
|
149
|
-
output =
|
157
|
+
output = logoutput.string.lines
|
150
158
|
|
151
159
|
expect(output.count).to eq sample_out.count
|
152
160
|
output.each_with_index do |o, i|
|
153
161
|
expect(o.strip).to match(/#{Regexp.escape sample_out[i].strip}$/)
|
154
162
|
end
|
155
163
|
|
156
|
-
expect(@run.summary['DEBUG']).to eq 57
|
157
|
-
expect(@run.log_history.count).to eq 8
|
158
|
-
expect(@run.status_log.count).to eq 6
|
159
|
-
expect(@run.items.first.log_history.count).to eq 25
|
160
|
-
expect(@run.items.first.status_log.count).to eq 8
|
161
|
-
|
162
164
|
end
|
163
165
|
|
164
166
|
it 'find workflow' do
|
165
|
-
workflow
|
166
|
-
|
167
|
-
expect(
|
168
|
-
expect(
|
169
|
-
expect(
|
170
|
-
expect(
|
171
|
-
expect(
|
172
|
-
expect(
|
173
|
-
expect(
|
174
|
-
expect(
|
175
|
-
expect(
|
176
|
-
expect(
|
177
|
-
expect(
|
178
|
-
expect(
|
179
|
-
expect(
|
180
|
-
expect(
|
181
|
-
expect(
|
167
|
+
workflow
|
168
|
+
wf = TestWorkflow.first
|
169
|
+
expect(wf.nil?).to eq false
|
170
|
+
expect(wf.name).to eq 'TestWorkflow'
|
171
|
+
expect(wf.description).to eq 'Workflow for testing'
|
172
|
+
expect(wf.input.count).to eq 2
|
173
|
+
expect(wf.input[:dirname][:default]).to eq '.'
|
174
|
+
expect(wf.config[:tasks].count).to eq 3
|
175
|
+
expect(wf.config[:tasks][0][:class]).to eq 'CollectFiles'
|
176
|
+
expect(wf.config[:tasks][0][:recursive]).to eq true
|
177
|
+
expect(wf.config[:tasks][1][:name]).to eq 'ProcessFiles'
|
178
|
+
expect(wf.config[:tasks][1][:subitems]).to eq true
|
179
|
+
expect(wf.config[:tasks][1][:tasks].count).to eq 2
|
180
|
+
expect(wf.config[:tasks][1][:tasks][0][:class]).to eq 'ChecksumTester'
|
181
|
+
expect(wf.config[:tasks][1][:tasks][0][:recursive]).to eq true
|
182
|
+
expect(wf.config[:tasks][1][:tasks][1][:class]).to eq 'CamelizeName'
|
183
|
+
expect(wf.config[:tasks][1][:tasks][1][:recursive]).to eq true
|
184
|
+
expect(wf.config[:tasks][2][:class]).to eq '::Libis::Workflow::Tasks::Analyzer'
|
182
185
|
end
|
183
186
|
|
184
187
|
# noinspection RubyResolve
|
185
188
|
it 'find run' do
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
expect(
|
191
|
-
expect(
|
192
|
-
expect(
|
193
|
-
expect(
|
194
|
-
expect(
|
195
|
-
expect(
|
189
|
+
run
|
190
|
+
wf = TestWorkflow.first
|
191
|
+
expect(wf.workflow_runs.count).to be > 0
|
192
|
+
wf_run = wf.workflow_runs.first
|
193
|
+
expect(wf_run.is_a? TestRun).to eq true
|
194
|
+
expect(wf_run.nil?).to eq false
|
195
|
+
expect(wf_run.options[:dirname]).to eq dirname
|
196
|
+
expect(wf_run.properties[:ingest_failed]).to eq false
|
197
|
+
expect(wf_run.log_history.count).to eq 8
|
198
|
+
expect(wf_run.status_log.count).to eq 6
|
199
|
+
expect(wf_run.summary[:DEBUG]).to eq 57
|
196
200
|
end
|
197
201
|
|
198
202
|
# noinspection RubyResolve
|
199
203
|
it 'find first item' do
|
200
|
-
|
201
|
-
|
202
|
-
|
204
|
+
run
|
205
|
+
wf = TestWorkflow.first
|
206
|
+
expect(wf.workflow_runs.first.items.count).to be > 0
|
207
|
+
item = wf.workflow_runs.first.items.first
|
203
208
|
expect(item.nil?).to eq false
|
204
209
|
expect(item.is_a? TestDirItem).to eq true
|
205
210
|
expect(item.properties[:name]).to eq 'Items'
|
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.beta.
|
4
|
+
version: 2.0.beta.8
|
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: libis-workflow
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- lib/libis/workflow/mongoid/base.rb
|
143
143
|
- lib/libis/workflow/mongoid/config.rb
|
144
144
|
- lib/libis/workflow/mongoid/run.rb
|
145
|
+
- lib/libis/workflow/mongoid/sequence.rb
|
145
146
|
- lib/libis/workflow/mongoid/version.rb
|
146
147
|
- lib/libis/workflow/mongoid/work_item.rb
|
147
148
|
- lib/libis/workflow/mongoid/work_item_base.rb
|