libis-workflow-mongoid 2.0.beta.10 → 2.0.beta.11

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: 72052cd9486d8810a3435fffb93cec07183a3660
4
- data.tar.gz: 3599ae44df1eec26ff057e6c8f41d3e31aba8acb
3
+ metadata.gz: cb77b9360af577f7b0b7f8067b0b43339a562512
4
+ data.tar.gz: 40868911a55787816c6cbd9e8e2730da9e26b1f4
5
5
  SHA512:
6
- metadata.gz: 4ca524054dd5a6224d420bd4669ccc2d4d6b712bbf067083b2fa4fb5b58463e343a0e13a4f8dba1a17a68f3dce7d1ae9839467b858aaba71000a320032acb598
7
- data.tar.gz: 75cf33dad01233954473c2fc2584dbc972f74b0779a62795b6caa1b0f01ce0bb93a6e456cfa91c47c6dc5d469def6937fe00c2afa896bdb2db0ea8348947b213
6
+ metadata.gz: 64a7f3c741675179200da3beaa66d02265611afabe19dc18e3f6f293e71b8bac1c9b077b021a26e4cb76c68f403fad2c45c8d4036ab4898654783d7553e9d7ef
7
+ data.tar.gz: ef4c92bc1aba840e0b7b609624203759557cea6fcbf65681a60ffae6c8131410d37d9d5ced04e988360715ead97cfb5aa3dff6517aa4813445e3f57734eb1d39
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ require 'libis/workflow/base/job'
4
+ require 'libis/workflow/mongoid/base'
5
+
6
+ module Libis
7
+ module Workflow
8
+ module Mongoid
9
+
10
+ module Job
11
+
12
+ def self.included(klass)
13
+ klass.class_eval do
14
+ include ::Libis::Workflow::Base::Job
15
+ include ::Libis::Workflow::Mongoid::Base
16
+
17
+ store_in collection: 'workflow_jobs'
18
+
19
+ field :name, type: String
20
+ field :description, type: String
21
+ field :input, type: Hash, default: -> { Hash.new }
22
+ field :run_object, type: String
23
+
24
+ index({name: 1}, {unique: 1})
25
+
26
+ def klass.run_class(run_klass)
27
+ has_many :runs, inverse_of: :job, class_name: run_klass.to_s,
28
+ dependent: :destroy, autosave: true, order: :c_at.asc
29
+ end
30
+
31
+ def klass.workflow_class(workflow_klass)
32
+ belongs_to :workflow, inverse_of: :jobs, class_name: workflow_klass.to_s
33
+ end
34
+
35
+ # def create_run_object
36
+ # # noinspection RubyResolve
37
+ # self.runs.build
38
+ # end
39
+
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+ end
@@ -20,22 +20,18 @@ module Libis
20
20
 
21
21
  field :start_date, type: Time, default: -> { Time.now }
22
22
 
23
- # def destroy
24
- # self.items.each { |item| item.destroy }
25
- # FileUtils.rmtree(work_dir) if Dir.exist?(work_dir)
26
- # super
27
- # end
28
-
29
23
  set_callback(:destroy, :before) do |document|
30
- wd = document.work_dir
31
- FileUtils.rmtree wd if Dir.exist? wd
32
24
  document.items.each { |item| item.destroy! }
25
+ wd = document.work_dir
26
+ FileUtils.rmtree wd if wd && !wd.blank? && Dir.exist?(wd)
27
+ id = document.properties[:ingest_dir]
28
+ FileUtils.rmtree id if id && !id.blank? && Dir.exist?(id)
33
29
  end
34
30
 
35
31
  index start_date: 1
36
32
 
37
- def klass.workflow_class(wf_klass)
38
- belongs_to :workflow, inverse_of: :workflow_runs, class_name: wf_klass.to_s
33
+ def klass.job_class(job_klass)
34
+ belongs_to :job, inverse_of: :runs, class_name: job_klass.to_s
39
35
  end
40
36
 
41
37
  def klass.item_class(item_klass)
@@ -45,11 +41,10 @@ module Libis
45
41
  end
46
42
  end
47
43
 
48
- def run(opts = {})
44
+ def run
49
45
  self.tasks = []
50
46
  self.items = []
51
- # noinspection RubySuperCallWithoutSuperclassInspection
52
- super opts
47
+ super
53
48
  end
54
49
 
55
50
  def restart(taskname)
@@ -3,7 +3,7 @@
3
3
  module Libis
4
4
  module Workflow
5
5
  module Mongoid
6
- VERSION = '2.0.beta.10' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
6
+ VERSION = '2.0.beta.11' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
7
7
  end
8
8
  end
9
9
  end
@@ -17,10 +17,6 @@ module Libis
17
17
  dependent: :destroy, autosave: true, order: :_id.asc
18
18
  belongs_to :parent, inverse_of: :items, class_name: klass.to_s
19
19
 
20
- # def destroy
21
- # self.items.each { |item| item.destroy! }
22
- # super
23
- # end
24
20
  set_callback(:destroy, :before) do |document|
25
21
  document.items.each { |item| item.destroy! }
26
22
  end
@@ -33,15 +29,15 @@ module Libis
33
29
  end
34
30
 
35
31
  def get_parent
36
- self[:parent] || self[:run]
32
+ self.parent || self.run
37
33
  end
38
34
 
39
35
  def get_run
40
- self[:run] || self[:parent].get_run
36
+ self.run || self.parent && self.parent.get_run || nil
41
37
  end
42
38
 
43
39
  def get_root
44
- self[:parent].get_root rescue self
40
+ self.parent && self.parent.get_root || self
45
41
  end
46
42
 
47
43
  end
@@ -23,9 +23,9 @@ module Libis
23
23
 
24
24
  index({name: 1}, {unique: 1})
25
25
 
26
- def klass.run_class(run_klass)
27
- has_many :workflow_runs, inverse_of: :workflow, class_name: run_klass.to_s,
28
- dependent: :destroy, autosave: true, order: :created_at.asc
26
+ def klass.job_class(job_klass)
27
+ has_many :jobs, inverse_of: :workflow, class_name: job_klass.to_s,
28
+ dependent: :destroy, autosave: true, order: :c_at.asc
29
29
  end
30
30
 
31
31
  def klass.load(file_or_hash)
@@ -37,19 +37,6 @@ module Libis
37
37
  workflow
38
38
  end
39
39
 
40
- def create_run_object
41
- # noinspection RubyResolve
42
- self.workflow_runs.build
43
- end
44
-
45
- def restart(id, task = nil)
46
- # noinspection RubyResolve
47
- run_object = self.workflow_runs.select { |run| run.id == id }
48
- raise WorkflowError, "Run #{id} not found" unless run_object
49
- run_object.restart task
50
- run_object
51
- end
52
-
53
40
  end
54
41
 
55
42
  end
@@ -11,6 +11,7 @@ module Libis
11
11
  autoload :Base, 'libis/workflow/mongoid/base'
12
12
  autoload :Config, 'libis/workflow/mongoid/config'
13
13
  autoload :LogEntry, 'libis/workflow/mongoid/log_entry'
14
+ autoload :Job, 'libis/workflow/mongoid/job'
14
15
  autoload :Run, 'libis/workflow/mongoid/run'
15
16
  autoload :WorkItem, 'libis/workflow/mongoid/work_item'
16
17
  autoload :WorkItemBase, 'libis/workflow/mongoid/work_item_base'
@@ -5,7 +5,7 @@ class TestRun
5
5
  include ::Libis::Workflow::Mongoid::Run
6
6
 
7
7
  item_class 'TestItem'
8
- workflow_class 'TestWorkflow'
8
+ job_class 'TestJob'
9
9
 
10
10
  def name; 'TestRun'; end
11
11
 
data/spec/test_job.rb ADDED
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require 'libis/workflow/mongoid/job'
4
+
5
+ class TestJob
6
+ include ::Libis::Workflow::Mongoid::Job
7
+ run_class 'TestRun'
8
+ workflow_class 'TestWorkflow'
9
+ end
@@ -4,5 +4,5 @@ require 'libis/workflow/mongoid/workflow'
4
4
 
5
5
  class TestWorkflow
6
6
  include ::Libis::Workflow::Mongoid::Workflow
7
- run_class 'TestRun'
7
+ job_class 'TestJob'
8
8
  end
@@ -6,6 +6,7 @@ require 'stringio'
6
6
  require 'libis-workflow-mongoid'
7
7
 
8
8
  require_relative 'spec_helper'
9
+ require_relative 'test_job'
9
10
  require_relative 'test_workflow'
10
11
  require_relative 'items'
11
12
 
@@ -53,16 +54,28 @@ describe 'TestWorkflow' do
53
54
  checksum_type: {default: 'SHA1', propagate_to: 'ProcessFiles/ChecksumTester'}
54
55
  }
55
56
  )
56
- # noinspection RubyResolve
57
- @workflow.workflow_runs.each { |run| run.destroy! }
58
57
  @workflow.save
59
- @run = @workflow.run(dirname: dirname, checksum_type: 'SHA256')
58
+
59
+ @job = TestJob.find_or_initialize_by(name: 'TestJob')
60
+ @job.configure(
61
+ name: 'TestJob',
62
+ description: 'Job for testing',
63
+ workflow: @workflow,
64
+ run_object: 'TestRun',
65
+ input: {dirname: dirname, checksum_type: 'SHA256'},
66
+ )
67
+
68
+ # noinspection RubyResolve
69
+ @job.runs.each { |run| run.destroy! }
70
+ @job.save
71
+ @run = @job.execute
60
72
 
61
73
  end
62
74
 
63
75
  def dirname; @dirname; end
64
76
  def logoutput; @logoutput; end
65
77
  def workflow; @workflow; end
78
+ def job; @job; end
66
79
  def run; @run; end
67
80
 
68
81
  it 'should contain three tasks' do
@@ -153,11 +166,11 @@ STR
153
166
 
154
167
  # noinspection RubyResolve
155
168
  it 'find run' do
156
- wf = TestWorkflow.first
157
- expect(wf).to eq workflow
158
- expect(workflow.workflow_runs.all.count).to eq 1
159
- wf_run = workflow.workflow_runs.all.first
160
- expect(wf_run).to eq run
169
+ my_job = TestJob.first
170
+ expect(my_job).to eq job
171
+ expect(my_job.runs.all.count).to eq 1
172
+ my_run = my_job.runs.all.first
173
+ expect(my_run).to eq run
161
174
  end
162
175
 
163
176
  # noinspection RubyResolve
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.10
4
+ version: 2.0.beta.11
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-10-21 00:00:00.000000000 Z
11
+ date: 2015-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libis-workflow
@@ -141,6 +141,7 @@ files:
141
141
  - lib/libis/workflow/mongoid.rb
142
142
  - lib/libis/workflow/mongoid/base.rb
143
143
  - lib/libis/workflow/mongoid/config.rb
144
+ - lib/libis/workflow/mongoid/job.rb
144
145
  - lib/libis/workflow/mongoid/log_entry.rb
145
146
  - lib/libis/workflow/mongoid/run.rb
146
147
  - lib/libis/workflow/mongoid/sequence.rb
@@ -162,6 +163,7 @@ files:
162
163
  - spec/tasks/camelize_name.rb
163
164
  - spec/tasks/checksum_tester.rb
164
165
  - spec/tasks/collect_files.rb
166
+ - spec/test_job.rb
165
167
  - spec/test_workflow.rb
166
168
  - spec/workflow_spec.rb
167
169
  homepage: https://github.com/libis/workflow-mongoid
@@ -200,5 +202,6 @@ test_files:
200
202
  - spec/tasks/camelize_name.rb
201
203
  - spec/tasks/checksum_tester.rb
202
204
  - spec/tasks/collect_files.rb
205
+ - spec/test_job.rb
203
206
  - spec/test_workflow.rb
204
207
  - spec/workflow_spec.rb