libis-workflow-mongoid 2.0.12 → 2.0.13
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/base.rb +4 -4
- data/lib/libis/workflow/mongoid/log_entry.rb +0 -3
- data/lib/libis/workflow/mongoid/status_entry.rb +27 -0
- data/lib/libis/workflow/mongoid/version.rb +1 -1
- data/lib/libis/workflow/mongoid/work_item.rb +12 -45
- data/lib/libis/workflow/mongoid.rb +1 -0
- data/spec/workflow_spec.rb +2 -7
- 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: 7ff731d84990f95728323e0a6fdd1c7ddccfacd6
|
4
|
+
data.tar.gz: 3bfdf421a6ad400bef46584cf5d52dbe6c22d330
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eac4a86f2b38c52699d951a1cb3037ad385a89fbab1aaf1280f8667bbcf9bd5dacb9476bcea87e9d56231a7bdade572bec7e140160a1d11c4b949dc04cb0ca9
|
7
|
+
data.tar.gz: a0e1206ac0063fc85ff9cf7f65e7500a01c11cbeefbc45f56be7f1ba0d6b7d4f2458ea16cac9f25c774f6d793738ce44b199c0a288048ac7282181c783b9bfcb
|
@@ -18,10 +18,10 @@ module Libis
|
|
18
18
|
|
19
19
|
include ::Mongoid::Document
|
20
20
|
include ::Mongoid::Timestamps::Created::Short
|
21
|
-
include ::Libis::Workflow::Mongoid::Sequence
|
22
|
-
|
23
|
-
field :_id, type: Integer, overwrite: true
|
24
|
-
sequence :_id
|
21
|
+
# include ::Libis::Workflow::Mongoid::Sequence
|
22
|
+
#
|
23
|
+
# field :_id, type: Integer, overwrite: true
|
24
|
+
# sequence :_id
|
25
25
|
index({c_at: 1}, {name: 'by_created'})
|
26
26
|
|
27
27
|
end
|
@@ -17,14 +17,11 @@ module Libis
|
|
17
17
|
field :task, type: String, default: ''
|
18
18
|
field :code, type: Integer
|
19
19
|
field :message, type: String
|
20
|
-
field :status, type: String
|
21
20
|
field :run_id
|
22
21
|
|
23
22
|
index({c_at: 1}, {name: 'by_created'})
|
24
23
|
index({logger_type: 1, logger_id: 1, c_at: 1, }, {background: true, name: 'by_logger'})
|
25
24
|
index({logger_type: 1, logger_id: 1, c_at: 1, task: 1}, {background: true, name: 'by_task'})
|
26
|
-
index({logger_type: 1, logger_id: 1, c_at: 1, status: 1}, {background: true, sparse: true, name: 'by_status'})
|
27
|
-
index({logger_type: 1, logger_id: 1, c_at: 1, task:1, status: 1}, {background: true, sparse: true, name: 'by_task_status'})
|
28
25
|
|
29
26
|
belongs_to :logger, polymorphic: true
|
30
27
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'libis-workflow'
|
2
|
+
require 'libis/workflow/mongoid/base'
|
3
|
+
|
4
|
+
require 'mongoid/extensions/time_with_zone'
|
5
|
+
|
6
|
+
module Libis
|
7
|
+
module Workflow
|
8
|
+
module Mongoid
|
9
|
+
|
10
|
+
class StatusEntry
|
11
|
+
include ::Mongoid::Document
|
12
|
+
include ::Mongoid::Timestamps::Short
|
13
|
+
|
14
|
+
field :task, type: String
|
15
|
+
field :status, type: String, default: 'STARTED'
|
16
|
+
field :progress, type: Integer
|
17
|
+
field :max, type: Integer
|
18
|
+
|
19
|
+
index({c_at: 1}, {name: 'by_created'})
|
20
|
+
index({u_at: 1}, {name: 'by_updated'})
|
21
|
+
|
22
|
+
embedded_in :item, polymorphic: true
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Libis
|
2
2
|
module Workflow
|
3
3
|
module Mongoid
|
4
|
-
VERSION = '2.0.
|
4
|
+
VERSION = '2.0.13' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
|
5
5
|
end
|
6
6
|
end
|
7
7
|
end
|
@@ -17,28 +17,7 @@ module Libis
|
|
17
17
|
|
18
18
|
index({_id: 1, _type: 1}, {unique: true, name: 'by_id'})
|
19
19
|
|
20
|
-
|
21
|
-
dependent: :destroy, autosave: true do
|
22
|
-
def log_history
|
23
|
-
where(:status.exists => false).order(c_at: 1)
|
24
|
-
end
|
25
|
-
|
26
|
-
def status_log(task = nil)
|
27
|
-
if task
|
28
|
-
where(:status.exists => true, task: task)
|
29
|
-
else
|
30
|
-
where(:status.exists => true)
|
31
|
-
end.order(c_at: 1)
|
32
|
-
end
|
33
|
-
|
34
|
-
def get_status(task = nil)
|
35
|
-
if task
|
36
|
-
where(:status.exists => true, task: task)
|
37
|
-
else
|
38
|
-
where(:status.exists => true)
|
39
|
-
end.order(c_at: -1).limit(1).first
|
40
|
-
end
|
41
|
-
end
|
20
|
+
embeds_many :status_log, as: :item, class_name: Libis::Workflow::Mongoid::StatusEntry.to_s
|
42
21
|
|
43
22
|
has_many :items, as: :parent, class_name: Libis::Workflow::Mongoid::WorkItem.to_s,
|
44
23
|
dependent: :destroy, autosave: true, order: :c_at.asc
|
@@ -47,21 +26,6 @@ module Libis
|
|
47
26
|
|
48
27
|
index({parent_id: 1, parent_type: 1, c_at: 1}, {name: 'by_parent'})
|
49
28
|
|
50
|
-
set_callback(:destroy, :before) do |document|
|
51
|
-
# noinspection RubyResolve
|
52
|
-
document.logs.each { |log| log.destroy! }
|
53
|
-
end
|
54
|
-
|
55
|
-
def log_history
|
56
|
-
# noinspection RubyResolve
|
57
|
-
self.logs.log_history.all || []
|
58
|
-
end
|
59
|
-
|
60
|
-
def status_log
|
61
|
-
# noinspection RubyResolve
|
62
|
-
self.logs.status_log.all || []
|
63
|
-
end
|
64
|
-
|
65
29
|
def add_item(item)
|
66
30
|
if item.parent
|
67
31
|
item.parent = nil
|
@@ -73,6 +37,13 @@ module Libis
|
|
73
37
|
self.items.to_a
|
74
38
|
end
|
75
39
|
|
40
|
+
def status_progress(task, progress = 0, max = nil)
|
41
|
+
log_entry = status_entry(task)
|
42
|
+
log_entry ||= self.status_log.build(task: task)
|
43
|
+
log_entry[:progress] = progress
|
44
|
+
log_entry[:max] = max if max
|
45
|
+
end
|
46
|
+
|
76
47
|
protected
|
77
48
|
|
78
49
|
# Get last known status entry for a given task
|
@@ -81,17 +52,13 @@ module Libis
|
|
81
52
|
# @param [String] task task name to check item status for
|
82
53
|
# @return [Hash] the status entry
|
83
54
|
def status_entry(task = nil)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
def add_log_entry(msg)
|
88
|
-
# noinspection RubyResolve
|
89
|
-
self.logs.build(msg)
|
55
|
+
task.nil? ?
|
56
|
+
self.status_log.order_by(u_at: -1).first :
|
57
|
+
self.status_log.order_by(u_at: -1).where(task: task).first
|
90
58
|
end
|
91
59
|
|
92
60
|
def add_status_log(info)
|
93
|
-
|
94
|
-
self.logs.build(info)
|
61
|
+
self.status_log.build(info)
|
95
62
|
end
|
96
63
|
|
97
64
|
end
|
@@ -9,6 +9,7 @@ module Libis
|
|
9
9
|
autoload :Base, 'libis/workflow/mongoid/base'
|
10
10
|
autoload :Config, 'libis/workflow/mongoid/config'
|
11
11
|
autoload :LogEntry, 'libis/workflow/mongoid/log_entry'
|
12
|
+
autoload :StatusEntry, 'libis/workflow/mongoid/status_entry'
|
12
13
|
autoload :Job, 'libis/workflow/mongoid/job'
|
13
14
|
autoload :WorkItem, 'libis/workflow/mongoid/work_item'
|
14
15
|
autoload :Run, 'libis/workflow/mongoid/run'
|
data/spec/workflow_spec.rb
CHANGED
@@ -160,13 +160,9 @@ STR
|
|
160
160
|
|
161
161
|
# puts output
|
162
162
|
|
163
|
-
expect(run.
|
164
|
-
expect(run.log_history.count).to eq 13
|
165
|
-
expect(run.status_log.count).to eq 10
|
163
|
+
expect(run.status_log.count).to eq 5
|
166
164
|
item = run.items.first
|
167
|
-
expect(item.
|
168
|
-
expect(item.status_log.count).to eq 6
|
169
|
-
expect(item.summary['DEBUG']).to eq 15
|
165
|
+
expect(item.status_log.count).to eq 3
|
170
166
|
|
171
167
|
expect(output.count).to eq sample_out.count
|
172
168
|
output.each_with_index do |o, i|
|
@@ -212,7 +208,6 @@ STR
|
|
212
208
|
expect(item.nil?).to eq false
|
213
209
|
expect(item.is_a? TestDirItem).to eq true
|
214
210
|
expect(item.properties['name']).to eq 'Items'
|
215
|
-
expect(item.properties['ingest_failed']).to eq false
|
216
211
|
end
|
217
212
|
|
218
213
|
it 'move item in relation' do
|
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.13
|
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-04-
|
11
|
+
date: 2016-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libis-workflow
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/libis/workflow/mongoid/log_entry.rb
|
119
119
|
- lib/libis/workflow/mongoid/run.rb
|
120
120
|
- lib/libis/workflow/mongoid/sequence.rb
|
121
|
+
- lib/libis/workflow/mongoid/status_entry.rb
|
121
122
|
- lib/libis/workflow/mongoid/version.rb
|
122
123
|
- lib/libis/workflow/mongoid/work_item.rb
|
123
124
|
- lib/libis/workflow/mongoid/worker.rb
|