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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91c8528db9e9f763f02b9f246e7a49378889729a
4
- data.tar.gz: b67569d5719ce03f0c27a944d59cd7999d0cc32c
3
+ metadata.gz: c58f0ada42f8b2fff98cdec7c60391e32f3b46cf
4
+ data.tar.gz: 995649c957d1b6763d99b92260d00a70aad91754
5
5
  SHA512:
6
- metadata.gz: 8278935845d10521aa8ac5e169be733512f8614988e6e43849b7fa88975dc9c41fb3100a176558abf7b0c5d649e9cd49e942e2ea9c1dd271a60dd171b44752bd
7
- data.tar.gz: 0fd3384e24e2c57f19a74f8b6934964a3397e3e149f90f12379b5cc2d8c04b3e66ecfede95a7f55a62f469e81312cdd4eafc41088c558f3a2dbaceb2eaf48973
6
+ metadata.gz: 0a39b24e484c371b36f67b60d3dd0e98ac30a2d5d23e8dbe69cb581df99bc71f0b9aee7752328ae50eec6a8e6d59298acd5c46c24d4dd3fc569a92e95de4e651
7
+ data.tar.gz: 166f3018b411aa524eaf02b653ebc68e17c08aaac8b4fb76ea0b325e31d5e410ca70b5ab0b6c1a6223a99178615e7c7c74c2fa73f80238d9b8844d1610abf653
@@ -22,7 +22,7 @@ module Libis
22
22
 
23
23
  field :_id, type: Integer, overwrite: true
24
24
  sequence :_id
25
- index c_at: 1
25
+ index({c_at: 1}, {name: 'by_created'})
26
26
 
27
27
  end
28
28
  end
@@ -28,7 +28,6 @@ module Libis
28
28
 
29
29
  field :_id, type: Integer, overwrite: true
30
30
  sequence :_id
31
- index _id: 1
32
31
 
33
32
  end
34
33
  end
@@ -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=' => true,
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, status: 1}, {background: true, sparse: true, name: 'status_by_logger'})
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.7' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
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, order: :c_at.asc do
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 status_log
25
- where(:status.exists => true)
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: :destroy, autosave: true, order: :c_at.asc
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|
@@ -60,15 +60,25 @@ describe 'TestWorkflow' do
60
60
  wf
61
61
  }
62
62
  let(:job) {
63
- job = TestJob.find_or_initialize_by(name: '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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libis-workflow-mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7
4
+ version: 2.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kris Dekeyser