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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6466278365e2209ba251617066ae6985e5f270e9
4
- data.tar.gz: 063440949f5164cbe98581f4a9d6c2e0864ec6ee
3
+ metadata.gz: cfa94b307591f08d69fad83f79bf8807c56037fd
4
+ data.tar.gz: d484aa41a3da41c6d6c282b073231b17faa6948d
5
5
  SHA512:
6
- metadata.gz: 9388dc7fb05308b629830cbf14431fc3489bed4f889124f045033b836bad926881225f4dd3785d373f29e1378ae595c4ad1b0e251f8f008f04efa7a1b506c442
7
- data.tar.gz: 85a40bff7f1b10f2ee7f6b2708a8c90cada57083d8e160ca9b5fd6f7042a39123faaa272a3a737c5a3ecdcaecced5d66f15dd591b180dfb859b762ee40004aa8
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.7.1' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
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: 'workflow_defintions'
17
+ store_in collection: 'workflow_definitions'
18
18
 
19
19
  field :name, type: String
20
20
  field :description, type: String
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'libis-workflow'
4
4
 
5
+ require_relative 'mongoid/version'
6
+
5
7
  module Libis
6
8
  module Workflow
7
9
  module Mongoid
@@ -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 = options[: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|
@@ -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, options[:location])
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 options[:subdirs]
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
- options[:selection] && !options[:selection].empty? ? x =~ Regexp.new(options[:selection]) : true
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
- Item.new
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
@@ -9,21 +9,21 @@ require_relative 'spec_helper'
9
9
  require_relative 'test_workflow'
10
10
  require_relative 'items'
11
11
 
12
- DIRNAME = 'spec/items'
12
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
13
13
 
14
14
  describe 'TestWorkflow' do
15
15
 
16
- before :all do
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
- @logoutput = StringIO.new
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 @logoutput
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
- @workflow = TestWorkflow.new
40
- @workflow.configure(
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
- @workflow.save
59
+ workflow.save
60
+ workflow
61
+ }
60
62
 
63
+ let(:run) {
61
64
  # noinspection RubyStringKeysInHashInspection
62
- @run = @workflow.run(dirname: DIRNAME, checksum_type: 'SHA256')
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(@workflow.config[:tasks].size).to eq 3
69
- expect(@workflow.config[:tasks].first[:class]).to eq 'CollectFiles'
70
- expect(@workflow.config[:tasks].last[:class]).to eq '::Libis::Workflow::Tasks::Analyzer'
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(@run.options[:dirname]).to eq DIRNAME
77
- expect(@run.items.count).to eq 1
78
- expect(@run.items.first.class).to eq TestDirItem
79
- expect(@run.items.first.count).to eq 4
80
- expect(@run.items.first.first.class).to eq TestFileItem
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
- @run.items.first.each_with_index do |x, i|
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 = @logoutput.string.lines
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 = TestWorkflow.first
166
- expect(workflow.nil?).to eq false
167
- expect(workflow.name).to eq 'TestWorkflow'
168
- expect(workflow.description).to eq 'Workflow for testing'
169
- expect(workflow.input.count).to eq 2
170
- expect(workflow.input[:dirname][:default]).to eq '.'
171
- expect(workflow.config[:tasks].count).to eq 3
172
- expect(workflow.config[:tasks][0][:class]).to eq 'CollectFiles'
173
- expect(workflow.config[:tasks][0][:recursive]).to eq true
174
- expect(workflow.config[:tasks][1][:name]).to eq 'ProcessFiles'
175
- expect(workflow.config[:tasks][1][:subitems]).to eq true
176
- expect(workflow.config[:tasks][1][:tasks].count).to eq 2
177
- expect(workflow.config[:tasks][1][:tasks][0][:class]).to eq 'ChecksumTester'
178
- expect(workflow.config[:tasks][1][:tasks][0][:recursive]).to eq true
179
- expect(workflow.config[:tasks][1][:tasks][1][:class]).to eq 'CamelizeName'
180
- expect(workflow.config[:tasks][1][:tasks][1][:recursive]).to eq true
181
- expect(workflow.config[:tasks][2][:class]).to eq '::Libis::Workflow::Tasks::Analyzer'
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
- workflow = TestWorkflow.first
187
- expect(workflow.workflow_runs.count).to be > 0
188
- run = workflow.workflow_runs.first
189
- expect(run.is_a? TestRun).to eq true
190
- expect(run.nil?).to eq false
191
- expect(run.options[:dirname]).to eq 'spec/items'
192
- expect(run.properties[:ingest_failed]).to eq false
193
- expect(run.log_history.count).to eq 8
194
- expect(run.status_log.count).to eq 6
195
- expect(run.summary[:DEBUG]).to eq 57
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
- workflow = TestWorkflow.first
201
- expect(workflow.workflow_runs.first.items.count).to be > 0
202
- item = workflow.workflow_runs.first.items.first
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.7.1
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-15 00:00:00.000000000 Z
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