libis-workflow 2.0.6 → 2.0.7

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: dfab02f94fe4c007febd5cb3a6a3f90bc690578d
4
- data.tar.gz: b28951ed4a7d771c600f8c1b80b47c5c708bc5b7
3
+ metadata.gz: 9327567da6093380f849f0deacb992873af61e60
4
+ data.tar.gz: 5478d89b9e65716195e371dd0dcb667b89445161
5
5
  SHA512:
6
- metadata.gz: f880d8a3daaf98ab41826055e8c9138146c253cd4a63af933302ee1277253e94b51a3ddd71175c6351eff24f54ef1b02eb4c953363b260077f8172fe302938ef
7
- data.tar.gz: 65ecec01867987ee515d8af5e5f9b2aa4a6cd274fcf0343bd04a2221d1c0438bcbd95a50cdbd517459c8d226750ffd30d45e08ec684af54927b2f85ab20b5305
6
+ metadata.gz: 72ffe0fcc00964f7ec170d4b8595d220c0f9027735f22c8b76d6fa000c96ea4681854abb91452f13c274b6161b6deeaa9b9c59dfdc4efd0e9d72994b2778de25
7
+ data.tar.gz: 26accfb461c22d93319bf955eed26ff3dbbd60fe2de62b4debd32f5e73bfd04d7ced849b55412a6d9db89ea73af02bf05fd556f4990c127fad1d9d7c04c8d216
@@ -11,11 +11,11 @@ module Libis
11
11
  include Libis::Workflow::Base::WorkItem
12
12
 
13
13
  def filename
14
- File.basename(self.properties[:filename]) || self.properties[:link]
14
+ File.basename(self.properties['filename']) || self.properties['link']
15
15
  end
16
16
 
17
17
  def name
18
- self.properties[:name] || self.filename
18
+ self.properties['name'] || self.filename
19
19
  end
20
20
 
21
21
  def filelist
@@ -27,40 +27,40 @@ module Libis
27
27
  end
28
28
 
29
29
  def fullpath
30
- self.properties[:filename]
30
+ self.properties['filename']
31
31
  end
32
32
 
33
33
  def filename=(name)
34
34
  begin
35
35
  stats = ::File.stat name
36
- self.properties[:size] = stats.size
37
- self.properties[:access_time] = stats.atime
38
- self.properties[:modification_time] = stats.mtime
39
- self.properties[:creation_time] = stats.ctime
40
- self.properties[:mode] = stats.mode
41
- self.properties[:uid] = stats.uid
42
- self.properties[:gid] = stats.gid
36
+ self.properties['size'] = stats.size
37
+ self.properties['access_time'] = stats.atime
38
+ self.properties['modification_time'] = stats.mtime
39
+ self.properties['creation_time'] = stats.ctime
40
+ self.properties['mode'] = stats.mode
41
+ self.properties['uid'] = stats.uid
42
+ self.properties['gid'] = stats.gid
43
43
  set_checksum(:MD5, ::Digest::MD5.hexdigest(File.read(name))) if File.file?(name)
44
44
  rescue
45
45
  # ignored
46
46
  end
47
- self.properties[:filename] = name
47
+ self.properties['filename'] = name
48
48
  end
49
49
 
50
50
  def checksum(checksum_type)
51
- self.properties[('checksum_' + checksum_type.to_s.downcase).to_sym]
51
+ self.properties[('checksum_' + checksum_type.to_s.downcase)]
52
52
  end
53
53
 
54
54
  def set_checksum(checksum_type, value)
55
- self.properties[('checksum_' + checksum_type.to_s.downcase).to_sym] = value
55
+ self.properties[('checksum_' + checksum_type.to_s.downcase)] = value
56
56
  end
57
57
 
58
58
  def link
59
- self.properties[:link]
59
+ self.properties['link']
60
60
  end
61
61
 
62
62
  def link=(name)
63
- self.properties[:link] = name
63
+ self.properties['link'] = name
64
64
  end
65
65
 
66
66
  def set_info(info)
@@ -47,11 +47,11 @@ module Libis
47
47
  self.name ||= ''
48
48
  self.description ||= ''
49
49
  self.input ||= {}
50
- self.name = cfg[:name] if cfg.has_key?(:name)
51
- self.description = cfg[:description] if cfg.has_key?(:description)
52
- self.workflow = cfg[:workflow] if cfg.has_key?(:workflow)
53
- self.run_object = cfg[:run_object] if cfg.has_key?(:run_object)
54
- self.input.merge!(cfg[:input] || {})
50
+ self.name = cfg['name'] if cfg.has_key?('name')
51
+ self.description = cfg['description'] if cfg.has_key?('description')
52
+ self.workflow = cfg['workflow'] if cfg.has_key?('workflow')
53
+ self.run_object = cfg['run_object'] if cfg.has_key?('run_object')
54
+ self.input.merge!(cfg['input'] || {})
55
55
  end
56
56
 
57
57
  # noinspection RubyResolve
@@ -61,10 +61,9 @@ module Libis
61
61
  raise RuntimeError.new "Could not create instance of run object '#{self.run_object}'" unless run
62
62
 
63
63
  run.job = self
64
- opts.key_strings_to_symbols!(recursive: true)
65
- (opts.delete(:run_config) || {}).each { |key,value| run.send(key, value) }
66
- run.options.merge!(self.input.merge(opts))
67
- run.save
64
+ (opts.delete('run_config') || {}).each { |key,value| run.send(key, value) }
65
+ run.options = self.input.merge(opts)
66
+ run.save!
68
67
 
69
68
  run.run
70
69
 
@@ -40,7 +40,7 @@ module Libis
40
40
  def add_log(message = {})
41
41
  msg = message_struct(message)
42
42
  add_log_entry(msg)
43
- self.save
43
+ self.save!
44
44
  end
45
45
 
46
46
  def <=(message = {})
@@ -48,7 +48,7 @@ module Libis
48
48
  end
49
49
 
50
50
  def logger
51
- self.properties[:logger] || self.job.logger rescue ::Libis::Workflow::Config.logger
51
+ self.properties['logger'] || self.job.logger rescue ::Libis::Workflow::Config.logger
52
52
  end
53
53
 
54
54
  # Execute the workflow.
@@ -81,7 +81,7 @@ module Libis
81
81
  # @return [String] string identification for this work item.
82
82
  def name
83
83
  # noinspection RubyResolve
84
- self.properties[:name] || self.inspect
84
+ self.properties['name'] || self.inspect
85
85
  end
86
86
 
87
87
  def to_s;
@@ -76,28 +76,29 @@ module Libis
76
76
  end
77
77
 
78
78
  def configure(cfg)
79
- self.name = cfg.delete(:name) || self.class.name
80
- self.description = cfg.delete(:description) || ''
81
- self.config.merge! input: {}, tasks: []
79
+ self.name = cfg.delete('name') || self.class.name
80
+ self.description = cfg.delete('description') || ''
81
+ self.config['input'] = {}
82
+ self.config['tasks'] = []
82
83
  self.config.merge! cfg
83
84
 
84
85
  self.class.require_all
85
86
 
86
- unless !self.config[:tasks].empty? &&
87
- self.config[:tasks].last[:class] &&
88
- self.config[:tasks].last[:class].split('::').last == 'Analyzer'
89
- self.config[:tasks] << {class: '::Libis::Workflow::Tasks::Analyzer'}
87
+ unless !self.config['tasks'].empty? &&
88
+ self.config['tasks'].last['class'] &&
89
+ self.config['tasks'].last['class'].split('::').last == 'Analyzer'
90
+ self.config['tasks'] << {'class' => '::Libis::Workflow::Tasks::Analyzer'}
90
91
  end
91
92
 
92
93
  self.config
93
94
  end
94
95
 
95
96
  def input
96
- self.config[:input].inject({}) do |hash, input_def|
97
- name = input_def.first.to_sym
97
+ self.config.key_strings_to_symbols(recursive: true)[:input].inject({}) do |hash, input_def|
98
+ name = input_def.first
98
99
  default = input_def.last[:default]
99
100
  parameter = ::Libis::Tools::Parameter.new name, default
100
- input_def.last.each { |k, v| parameter[k.to_sym] = v }
101
+ input_def.last.each { |k, v| parameter[k] = v }
101
102
  hash[name] = parameter
102
103
  hash
103
104
  end
@@ -107,6 +108,7 @@ module Libis
107
108
 
108
109
  # @param [Hash] options
109
110
  def prepare_input(options)
111
+ options = options.key_strings_to_symbols
110
112
  result = {}
111
113
  self.input.each do |key, parameter|
112
114
  if options.has_key?(key)
@@ -122,7 +124,7 @@ module Libis
122
124
  result[key] = value if propagate_to.empty?
123
125
  propagate_to.each do |target|
124
126
  task_name, param_name = target.split('#')
125
- param_name ||= key
127
+ param_name ||= key.to_s
126
128
  result[task_name] ||= {}
127
129
  result[task_name][param_name] = value
128
130
  end
@@ -131,17 +133,17 @@ module Libis
131
133
  end
132
134
 
133
135
  def tasks(parent = nil)
134
- self.config[:tasks].map do |cfg|
136
+ self.config['tasks'].map do |cfg|
135
137
  instantize_task(parent || nil, cfg)
136
138
  end
137
139
  end
138
140
 
139
141
  def instantize_task(parent, cfg)
140
142
  task_class = Libis::Workflow::TaskGroup
141
- task_class = cfg[:class].constantize if cfg[:class]
143
+ task_class = cfg['class'].constantize if cfg['class']
142
144
  # noinspection RubyArgCount
143
145
  task_instance = task_class.new(parent, cfg)
144
- cfg[:tasks] && cfg[:tasks].map do |task_cfg|
146
+ cfg['tasks'] && cfg['tasks'].map do |task_cfg|
145
147
  task_instance << instantize_task(task_instance, task_cfg)
146
148
  end
147
149
  task_instance
@@ -17,7 +17,7 @@ module Libis
17
17
  def status=(x)
18
18
  s, task = x
19
19
  self.add_status_log(task: task, status: s)
20
- self.save
20
+ self.save!
21
21
  end
22
22
 
23
23
  # Get last known status symbol for a given task
@@ -17,7 +17,7 @@ module Libis
17
17
 
18
18
  attr_accessor :parent, :name, :workitem
19
19
 
20
- parameter quiet: false, description: 'Prevemt generating log output.'
20
+ parameter quiet: false, description: 'Prevent generating log output.'
21
21
  parameter recursive: false, description: 'Run the task on all subitems recursively.'
22
22
  parameter retry_count: 0, description: 'Number of times to retry the task if waiting for another process.'
23
23
  parameter retry_interval: 10, description: 'Number of seconds to wait between retries.'
@@ -44,7 +44,10 @@ module Libis
44
44
 
45
45
  case self.action
46
46
  when :retry
47
- return if item.check_status(:DONE, self.namepath)
47
+ if item.check_status(:DONE, self.namepath)
48
+ debug 'Retry: skipping task %s because it has finished successfully.', item, self.namepath
49
+ return
50
+ end
48
51
  when :failed
49
52
  return
50
53
  else
@@ -90,7 +93,7 @@ module Libis
90
93
  debug e.backtrace.join("\n")
91
94
 
92
95
  ensure
93
- item.save
96
+ item.save!
94
97
 
95
98
  end
96
99
 
@@ -106,7 +109,6 @@ module Libis
106
109
  o = {}
107
110
  o.merge!(opts[self.class.to_s] || {})
108
111
  o.merge!(opts[self.name] || opts[self.names.join('/')] || {})
109
- o.key_symbols_to_strings!
110
112
 
111
113
  if o and o.is_a? Hash
112
114
  default_values.each do |name, _|
@@ -144,12 +146,13 @@ module Libis
144
146
  def logger
145
147
  (self.parent || self.get_run).logger
146
148
  end
149
+
147
150
  protected
148
151
 
149
152
  def configure(cfg)
150
- self.name = cfg[:name] || (cfg[:class] || self.class).to_s.split('::').last
151
- (cfg[:options] || {}).merge(
152
- cfg.reject { |k, _| [:options, :name, :class].include? k.to_sym }
153
+ self.name = cfg['name'] || (cfg['class'] || self.class).to_s.split('::').last
154
+ (cfg['options'] || {}).merge(
155
+ cfg.reject { |k, _| %w(options name class).include? k }
153
156
  ).symbolize_keys.each do |k, v|
154
157
  self.parameter(k, v)
155
158
  end
@@ -12,7 +12,7 @@ module Libis
12
12
  # @param [Libis::Workflow::Base::WorkItem] item
13
13
  def run(item)
14
14
 
15
- item.properties[:ingest_failed] = item.check_status(:FAILED)
15
+ item.properties['ingest_failed'] = item.check_status(:FAILED)
16
16
 
17
17
  item.summary = {}
18
18
  item.log_history.each do |log|
@@ -36,7 +36,7 @@ module Libis
36
36
 
37
37
  ensure
38
38
 
39
- item.save
39
+ item.save!
40
40
 
41
41
  end
42
42
 
@@ -1,5 +1,5 @@
1
1
  module Libis
2
2
  module Workflow
3
- VERSION = '2.0.6' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
3
+ VERSION = '2.0.7' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  require 'sidekiq'
2
2
 
3
+ require 'libis/tools/extend/hash'
3
4
  require 'libis/workflow/config'
4
5
  require 'libis/workflow/workflow'
5
6
 
@@ -31,7 +32,7 @@ module Libis
31
32
 
32
33
  def get_job(job_config)
33
34
  job = ::Libis::Workflow::Job.new
34
- job.configure job_config
35
+ job.configure job_config.key_symbols_to_strings(recursive: true)
35
36
  job
36
37
  end
37
38
 
@@ -24,21 +24,21 @@ describe 'TestWorkflow' do
24
24
  let(:workflow) {
25
25
  workflow = ::Libis::Workflow::Workflow.new
26
26
  workflow.configure(
27
- name: 'TestWorkflow',
28
- description: 'Workflow for testing',
29
- tasks: [
30
- {class: 'CollectFiles', recursive: true},
27
+ 'name' => 'TestWorkflow',
28
+ 'description' => 'Workflow for testing',
29
+ 'tasks' => [
30
+ {'class' => 'CollectFiles', 'recursive' => true},
31
31
  {
32
- name: 'ProcessFiles', recursive: false,
33
- tasks: [
34
- {class: 'ChecksumTester', recursive: true},
35
- {class: 'CamelizeName', recursive: true}
32
+ 'name' => 'ProcessFiles', 'recursive' => false,
33
+ 'tasks' => [
34
+ {'class' => 'ChecksumTester', 'recursive' => true},
35
+ {'class' => 'CamelizeName', 'recursive' => true}
36
36
  ]
37
37
  }
38
38
  ],
39
- input: {
40
- dirname: {default: '.', propagate_to: 'CollectFiles#location'},
41
- checksum_type: {default: 'SHA1', propagate_to: 'ChecksumTester'}
39
+ 'input' => {
40
+ 'dirname' => {'default' => '.', 'propagate_to' => 'CollectFiles#location'},
41
+ 'checksum_type' => {'default' => 'SHA1', 'propagate_to' => 'ChecksumTester'}
42
42
  }
43
43
  )
44
44
  workflow
@@ -47,19 +47,19 @@ describe 'TestWorkflow' do
47
47
  let(:job) {
48
48
  job = ::Libis::Workflow::Job.new
49
49
  job.configure(
50
- name: 'TestJob',
51
- description: 'Job for testing',
52
- workflow: workflow,
53
- run_object: 'TestRun',
54
- input: {dirname: dirname, checksum_type: 'SHA256'},
50
+ 'name' => 'TestJob',
51
+ 'description' => 'Job for testing',
52
+ 'workflow' => workflow,
53
+ 'run_object' => 'TestRun',
54
+ 'input' => {'dirname' => dirname, 'checksum_type' => 'SHA256'},
55
55
  )
56
56
  job
57
57
  }
58
58
 
59
59
  it 'should contain three tasks' do
60
- expect(workflow.config[:tasks].size).to eq 3
61
- expect(workflow.config[:tasks].first[:class]).to eq 'CollectFiles'
62
- expect(workflow.config[:tasks].last[:class]).to eq '::Libis::Workflow::Tasks::Analyzer'
60
+ expect(workflow.config['tasks'].size).to eq 3
61
+ expect(workflow.config['tasks'].first['class']).to eq 'CollectFiles'
62
+ expect(workflow.config['tasks'].last['class']).to eq '::Libis::Workflow::Tasks::Analyzer'
63
63
  end
64
64
 
65
65
  # noinspection RubyResolve
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libis-workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.0.7
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-03-11 00:00:00.000000000 Z
11
+ date: 2016-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler