libis-workflow-mongoid 2.0.7 → 2.0.8
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 +1 -1
- data/lib/libis/workflow/mongoid/dynamic.rb +0 -1
- data/lib/libis/workflow/mongoid/job.rb +6 -5
- data/lib/libis/workflow/mongoid/log_entry.rb +3 -3
- data/lib/libis/workflow/mongoid/run.rb +6 -5
- data/lib/libis/workflow/mongoid/version.rb +1 -1
- data/lib/libis/workflow/mongoid/work_item.rb +29 -4
- data/lib/libis/workflow/mongoid/workflow.rb +2 -2
- data/spec/workflow_spec.rb +13 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c58f0ada42f8b2fff98cdec7c60391e32f3b46cf
|
4
|
+
data.tar.gz: 995649c957d1b6763d99b92260d00a70aad91754
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a39b24e484c371b36f67b60d3dd0e98ac30a2d5d23e8dbe69cb581df99bc71f0b9aee7752328ae50eec6a8e6d59298acd5c46c24d4dd3fc569a92e95de4e651
|
7
|
+
data.tar.gz: 166f3018b411aa524eaf02b653ebc68e17c08aaac8b4fb76ea0b325e31d5e410ca70b5ab0b6c1a6223a99178615e7c7c74c2fa73f80238d9b8844d1610abf653
|
@@ -22,21 +22,22 @@ module Libis
|
|
22
22
|
field :log_age, type: String, default: 'daily'
|
23
23
|
field :log_keep, type: Integer, default: 5
|
24
24
|
|
25
|
-
index({name: 1}, {unique: 1})
|
25
|
+
index({name: 1}, {unique: 1, name: 'by_name'})
|
26
26
|
|
27
27
|
has_many :runs, as: :job, dependent: :destroy, autosave: true, order: :c_at.asc
|
28
|
-
|
29
28
|
belongs_to :workflow, polymorphic: true
|
30
29
|
|
30
|
+
index({workflow_id: 1, workflow_type: 1, name: 1}, {name: 'by_workflow'})
|
31
|
+
|
31
32
|
def self.from_hash(hash)
|
32
33
|
self.create_from_hash(hash, [:name]) do |item, cfg|
|
33
|
-
item.workflow = Libis::Workflow::Mongoid.from_hash(name: cfg.delete('workflow'))
|
34
|
+
item.workflow = Libis::Workflow::Mongoid::Workflow.from_hash(name: cfg.delete('workflow'))
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
38
|
def logger
|
38
39
|
return ::Libis::Workflow::Mongoid::Config.logger unless self.log_to_file
|
39
|
-
logger = ::Logging::Repository[self.name]
|
40
|
+
logger = ::Logging::Repository.instance[self.name]
|
40
41
|
return logger if logger
|
41
42
|
unless ::Logging::Appenders[self.name]
|
42
43
|
::Logging::Appenders::RollingFile.new(
|
@@ -59,7 +60,7 @@ module Libis
|
|
59
60
|
def execute(opts = {})
|
60
61
|
if self.log_each_run
|
61
62
|
opts['run_config'] = {
|
62
|
-
'log_to_file
|
63
|
+
'log_to_file' => true,
|
63
64
|
'log_level=' => self.log_level
|
64
65
|
}
|
65
66
|
end
|
@@ -19,10 +19,10 @@ module Libis
|
|
19
19
|
field :status, type: String
|
20
20
|
field :run_id
|
21
21
|
|
22
|
-
index({logger_type: 1, logger_id: 1, c_at: 1}, {background: true, name: 'by_logger'})
|
23
|
-
index({logger_type: 1, logger_id: 1, c_at: 1, task: 1}, {background: true, name: 'by_logger_task'})
|
24
22
|
index({logger_type: 1, logger_id: 1, c_at: 1, }, {background: true, name: 'by_logger'})
|
25
|
-
index({logger_type: 1, logger_id: 1, c_at: 1,
|
23
|
+
index({logger_type: 1, logger_id: 1, c_at: 1, task: 1}, {background: true, name: 'by_task'})
|
24
|
+
index({logger_type: 1, logger_id: 1, c_at: 1, status: 1}, {background: true, sparse: true, name: 'by_status'})
|
25
|
+
index({logger_type: 1, logger_id: 1, c_at: 1, task:1, status: 1}, {background: true, sparse: true, name: 'by_task_status'})
|
26
26
|
|
27
27
|
belongs_to :logger, polymorphic: true
|
28
28
|
|
@@ -15,6 +15,12 @@ module Libis
|
|
15
15
|
field :log_level, type: String, default: 'DEBUG'
|
16
16
|
field :log_filename, type: String
|
17
17
|
|
18
|
+
index({start_date: 1}, {sparse: 1, name: 'by_start'})
|
19
|
+
|
20
|
+
belongs_to :job, polymorphic: true
|
21
|
+
|
22
|
+
index({job_id: 1, job_type: 1, start_date: 1}, {sparse:1, name: 'by_job'})
|
23
|
+
|
18
24
|
set_callback(:destroy, :before) do |document|
|
19
25
|
wd = document.work_dir
|
20
26
|
FileUtils.rmtree wd if wd && !wd.blank? && Dir.exist?(wd)
|
@@ -23,11 +29,6 @@ module Libis
|
|
23
29
|
FileUtils.rm(log_file) if log_file && !log_file.blank? && File.exist?(log_file)
|
24
30
|
end
|
25
31
|
|
26
|
-
index start_date: 1
|
27
|
-
|
28
|
-
belongs_to :job, polymorphic: true
|
29
|
-
embeds_one :log_config, as: :log_configurator
|
30
|
-
|
31
32
|
def run(action = :run)
|
32
33
|
self.tasks = []
|
33
34
|
super action
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Libis
|
2
2
|
module Workflow
|
3
3
|
module Mongoid
|
4
|
-
VERSION = '2.0.
|
4
|
+
VERSION = '2.0.8' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
|
5
5
|
end
|
6
6
|
end
|
7
7
|
end
|
@@ -15,14 +15,28 @@ module Libis
|
|
15
15
|
field :properties, type: Hash, default: -> { Hash.new }
|
16
16
|
field :summary, type: Hash, default: -> { Hash.new }
|
17
17
|
|
18
|
+
index({_id: 1, _type: 1}, {unique: true, name: 'by_id'})
|
19
|
+
|
18
20
|
has_many :logs, as: :logger, class_name: Libis::Workflow::Mongoid::LogEntry.to_s,
|
19
|
-
dependent: :destroy, autosave: true
|
21
|
+
dependent: :destroy, autosave: true do
|
20
22
|
def log_history
|
21
|
-
where(:status.exists => false)
|
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)
|
22
32
|
end
|
23
33
|
|
24
|
-
def
|
25
|
-
|
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
|
26
40
|
end
|
27
41
|
end
|
28
42
|
|
@@ -31,6 +45,8 @@ module Libis
|
|
31
45
|
|
32
46
|
belongs_to :parent, polymorphic: true
|
33
47
|
|
48
|
+
index({parent_id: 1, parent_type: 1, c_at: 1}, {name: 'by_parent'})
|
49
|
+
|
34
50
|
set_callback(:destroy, :before) do |document|
|
35
51
|
# noinspection RubyResolve
|
36
52
|
document.logs.each { |log| log.destroy! }
|
@@ -59,6 +75,15 @@ module Libis
|
|
59
75
|
|
60
76
|
protected
|
61
77
|
|
78
|
+
# Get last known status entry for a given task
|
79
|
+
#
|
80
|
+
# In the Mongid storage, we retrieve the status log in date descending order, so we retrieve the first item.
|
81
|
+
# @param [String] task task name to check item status for
|
82
|
+
# @return [Hash] the status entry
|
83
|
+
def status_entry(task = nil)
|
84
|
+
self.logs.get_status(task)
|
85
|
+
end
|
86
|
+
|
62
87
|
def add_log_entry(msg)
|
63
88
|
# noinspection RubyResolve
|
64
89
|
self.logs.build(msg)
|
@@ -18,9 +18,9 @@ module Libis
|
|
18
18
|
field :description, type: String
|
19
19
|
field :config, type: Hash, default: -> { Hash.new }
|
20
20
|
|
21
|
-
index({name: 1}, {unique: 1})
|
21
|
+
index({name: 1}, {unique: 1, name: 'by_name'})
|
22
22
|
|
23
|
-
has_many :jobs, as: :workflow, dependent: :
|
23
|
+
has_many :jobs, as: :workflow, dependent: :restrict, autosave: true, order: :name.asc
|
24
24
|
|
25
25
|
def self.from_hash(hash)
|
26
26
|
self.create_from_hash(hash, [:name]) do |item, cfg|
|
data/spec/workflow_spec.rb
CHANGED
@@ -60,15 +60,25 @@ describe 'TestWorkflow' do
|
|
60
60
|
wf
|
61
61
|
}
|
62
62
|
let(:job) {
|
63
|
-
job = TestJob.
|
64
|
-
job.configure(
|
63
|
+
job = TestJob.from_hash(
|
65
64
|
'name' => 'TestJob',
|
66
65
|
'description' => 'Job for testing',
|
67
66
|
'workflow' => workflow,
|
68
67
|
'run_object' => 'TestRun',
|
69
68
|
'input' => {'dirname' => dirname, 'checksum_type' => 'SHA256'},
|
69
|
+
'log_to_file' => false
|
70
70
|
)
|
71
71
|
|
72
|
+
# job = TestJob.find_or_initialize_by(name: 'TestJob')
|
73
|
+
# job.configure(
|
74
|
+
# 'name' => 'TestJob',
|
75
|
+
# 'description' => 'Job for testing',
|
76
|
+
# 'workflow' => workflow,
|
77
|
+
# 'run_object' => 'TestRun',
|
78
|
+
# 'input' => {'dirname' => dirname, 'checksum_type' => 'SHA256'},
|
79
|
+
# 'log_to_file' => false
|
80
|
+
# )
|
81
|
+
|
72
82
|
# noinspection RubyResolve
|
73
83
|
job.runs.each { |run| run.destroy! }
|
74
84
|
job.save!
|
@@ -183,6 +193,7 @@ STR
|
|
183
193
|
expect(my_job.runs.all.count).to eq 1
|
184
194
|
my_run = my_job.runs.all.first
|
185
195
|
expect(my_run).to eq run
|
196
|
+
expect(my_run.status).to eq :DONE
|
186
197
|
end
|
187
198
|
|
188
199
|
# noinspection RubyResolve
|