libis-workflow 2.0.0 → 2.0.1

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: 91b0c182d5d2f5214287dc2cd50eb0a7b9f4fbd3
4
- data.tar.gz: 6c51f5afcd524d2314e05b5cf14f66aeb30e050b
3
+ metadata.gz: 4b3ce4d596ca40c95f30e64d6f739020bf19994b
4
+ data.tar.gz: 639124a5d3ba1474a390ddc8d396571c15d81e91
5
5
  SHA512:
6
- metadata.gz: c9c2b825f8ce8b5d6007975770e45694a8c6710ebc4a6f13cc37eb51810424c31867bfe8057195680893d68c8adf1e34a007c08257fbba198e5574423994a63f
7
- data.tar.gz: 9f248db1a5e6ceb17560ed91534535783abf295e0b27130688721d7746496e91b0a77996bfcac3ec503495839f1f21a25e163d7ada667dfc5957b8e7510cf1df
6
+ metadata.gz: 0d09e49198e9b416278ac074fb2e9a1cfa9eb19aaa9bc28348697b9c8cc2373bc059d12e743012519053fc6b102f0f74c3f4a364abbf6e14d033f11c2100f717
7
+ data.tar.gz: 7b71eeb726ba6b7aabf4faf7667b1770b1f35c7ca379fbc6197ebbc8c47cada61620639278ef108769792247244b44968707e8aeed5ab70a388999ebe7cd3c3e
@@ -3,25 +3,6 @@ module Libis
3
3
  module Base
4
4
  module Logging
5
5
 
6
- # Helper function for the WorkItems to add a log entry to the log_history.
7
- #
8
- # The supplied message structure is expected to contain the following fields:
9
- # - :severity : ::Logger::Severity value
10
- # - :id : optional message id
11
- # - :text : message text
12
- # - :task : list of tasks names (task hierarchy) that submits the message
13
- #
14
- # @param [Hash] message
15
- def add_log(message = {})
16
- msg = message_struct(message)
17
- add_log_entry(msg)
18
- self.save
19
- end
20
-
21
- def <=(message = {})
22
- self.add_log(message)
23
- end
24
-
25
6
  # Add a structured message to the log history. The message text can be submitted as an integer or text. If an
26
7
  # integer is submitted, it will be used to look up the text in the MessageRegistry. The message text will be
27
8
  # passed to the % operator with the args parameter. If that failes (e.g. because the format string is not correct)
@@ -45,31 +26,35 @@ module Libis
45
26
  run_id = self.get_run.id rescue nil
46
27
 
47
28
  self.add_log severity: severity, id: message_id.to_i, text: message_text, task: task, run_id: run_id
29
+ end
48
30
 
49
- task = "[#{run_id}] #{task}" if run_id
50
- name = ''
51
- begin
52
- name = self.to_s
53
- name = self.name
54
- name = self.namepath
55
- rescue
56
- # do nothing
57
- end
31
+ # Helper function for the WorkItems to add a log entry to the log_history.
32
+ #
33
+ # The supplied message structure is expected to contain the following fields:
34
+ # - :severity : ::Logger::Severity value
35
+ # - :id : optional message id
36
+ # - :text : message text
37
+ # - :task : list of tasks names (task hierarchy) that submits the message
38
+ #
39
+ # @param [Hash] message
40
+ def add_log(message = {})
41
+ msg = message_struct(message)
42
+ add_log_entry(msg)
43
+ self.save
44
+ end
58
45
 
59
- logger = self.get_run.logger rescue Config.logger
60
- logger.add(severity, message_text, ('%s - %s ' % [task, name]))
46
+ def <=(message = {})
47
+ self.add_log(message)
61
48
  end
62
49
 
63
50
  protected
64
51
 
65
- SEV_LABEL = %w(DEBUG INFO WARN ERROR FATAL ANY) unless const_defined? :SEV_LABEL
66
-
67
52
  # create and return a proper message structure
68
53
  # @param [Hash] opts
69
54
  def message_struct(opts = {})
70
- opts.reverse_merge!(severity: ::Logger::INFO, code: nil, text: '')
55
+ opts.reverse_merge!(severity: :info, code: nil, text: '')
71
56
  {
72
- severity: SEV_LABEL[opts[:severity]],
57
+ severity: ::Logging::levelify(opts[:severity]).upcase,
73
58
  task: opts[:task],
74
59
  code: opts[:code],
75
60
  message: opts[:text]
@@ -49,6 +49,10 @@ module Libis
49
49
  self.job.workflow
50
50
  end
51
51
 
52
+ def logger
53
+ self.properties['logger'] || self.job.logger rescue ::Libis::Workflow::Config.logger
54
+ end
55
+
52
56
  # Execute the workflow.
53
57
  #
54
58
  # The action parameter defines how the execution of the tasks will behave:
@@ -65,10 +69,9 @@ module Libis
65
69
 
66
70
  self.options = workflow.prepare_input(self.options)
67
71
 
68
- self.tasks = workflow.tasks(self)
72
+ self.tasks = workflow.tasks
69
73
  configure_tasks self.options
70
74
 
71
-
72
75
  self.tasks.each do |task|
73
76
  task.run self
74
77
  end
@@ -132,7 +132,7 @@ module Libis
132
132
 
133
133
  def tasks(parent = nil)
134
134
  self.config[:tasks].map do |cfg|
135
- instantize_task(parent || self, cfg)
135
+ instantize_task(parent || nil, cfg)
136
136
  end
137
137
  end
138
138
 
@@ -4,6 +4,7 @@ require 'backports/rails/string'
4
4
 
5
5
  require 'libis/tools/parameter'
6
6
  require 'libis/tools/extend/hash'
7
+ require 'libis/tools/logger'
7
8
 
8
9
  require 'libis/workflow'
9
10
 
@@ -12,7 +13,7 @@ module Libis
12
13
 
13
14
  # noinspection RubyTooManyMethodsInspection
14
15
  class Task
15
- include ::Libis::Workflow::Base::Logger
16
+ include ::Libis::Tools::Logger
16
17
  include ::Libis::Tools::ParameterContainer
17
18
 
18
19
  attr_accessor :parent, :name, :workitem
@@ -116,9 +117,33 @@ module Libis
116
117
  self.parameter(name.to_sym, value)
117
118
  end
118
119
  end
120
+ end
119
121
 
122
+ def message(severity, msg, *args)
123
+ taskname = self.namepath rescue nil
124
+ self.set_application(taskname)
125
+ item = self.workitem
126
+ item = args.shift if args.size > 0 and args[0].is_a?(::Libis::Workflow::Base::WorkItem)
127
+ if item
128
+ subject = nil
129
+ begin
130
+ subject = item.to_s
131
+ subject = item.name
132
+ subject = item.namepath
133
+ rescue
134
+ # do nothing
135
+ end
136
+ self.set_subject(subject)
137
+ item.log_message(
138
+ severity, msg.is_a?(Integer) ? {id: msg} : {text: (msg.to_s rescue '')}.merge(task: taskname), *args
139
+ )
140
+ end
141
+ super severity, msg, *args
120
142
  end
121
143
 
144
+ def logger
145
+ (self.parent || self.get_run).logger
146
+ end
122
147
  protected
123
148
 
124
149
  def configure(cfg)
@@ -204,11 +229,15 @@ module Libis
204
229
  end
205
230
 
206
231
  def action=(action)
207
- self.workitem.get_run.action = action
232
+ self.get_run.action = action
208
233
  end
209
234
 
210
235
  def action
211
- self.workitem.get_run.action
236
+ self.get_run.action
237
+ end
238
+
239
+ def get_run(item = nil)
240
+ get_root_item(item).get_run
212
241
  end
213
242
 
214
243
  def get_root_item(item = nil)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Libis
4
4
  module Workflow
5
- VERSION = '2.0.0' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
5
+ VERSION = '2.0.1' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
6
6
  end
7
7
  end
@@ -13,7 +13,6 @@ module Libis
13
13
  autoload :WorkItem, 'libis/workflow/base/work_item'
14
14
  autoload :FileItem, 'libis/workflow/base/file_item'
15
15
  autoload :DirItem, 'libis/workflow/base/dir_item'
16
- autoload :Logger, 'libis/workflow/base/logger'
17
16
  autoload :Logging, 'libis/workflow/base/logging'
18
17
  autoload :Job, 'libis/workflow/base/job'
19
18
  autoload :Run, 'libis/workflow/base/run'
@@ -4,21 +4,24 @@ require 'stringio'
4
4
 
5
5
  describe 'TestWorkflow' do
6
6
 
7
- let(:basedir) { File.absolute_path File.join(File.dirname(__FILE__)) }
8
- let(:dirname) { File.join(basedir, 'items') }
7
+ basedir = File.absolute_path File.join(File.dirname(__FILE__))
8
+ dirname = File.join(basedir, 'items')
9
9
 
10
- let(:logoutput) { StringIO.new }
10
+ before :each do
11
11
 
12
- let(:workflow) {
13
12
  # noinspection RubyResolve
14
13
  ::Libis::Workflow.configure do |cfg|
15
14
  cfg.itemdir = dirname
16
15
  cfg.taskdir = File.join(basedir, 'tasks')
17
16
  cfg.workdir = File.join(basedir, 'work')
18
- cfg.logger = Logger.new logoutput
19
- cfg.logger.level = Logger::DEBUG
17
+ cfg.logger.appenders =
18
+ ::Logging::Appenders.string_io('StringIO', layout: ::Libis::Tools::Config.get_log_formatter)
20
19
  end
20
+ end
21
+
22
+ let(:logoutput) { ::Libis::Workflow::Config.logger.appenders.first.sio }
21
23
 
24
+ let(:workflow) {
22
25
  workflow = ::Libis::Workflow::Workflow.new
23
26
  workflow.configure(
24
27
  name: 'TestWorkflow',
@@ -106,6 +109,8 @@ STR
106
109
  run = job.execute
107
110
  output = logoutput.string.lines.to_a
108
111
 
112
+ # puts output
113
+
109
114
  expect(output.size).to eq sample_out.size
110
115
  output.each_with_index do |o, i|
111
116
  expect(o[/(?<=\] ).*/]).to eq sample_out[i].strip
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.0
4
+ version: 2.0.1
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-03 00:00:00.000000000 Z
11
+ date: 2016-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -125,11 +125,9 @@ files:
125
125
  - lib/libis/exceptions.rb
126
126
  - lib/libis/workflow.rb
127
127
  - lib/libis/workflow/action.rb
128
- - lib/libis/workflow/base.rb
129
128
  - lib/libis/workflow/base/dir_item.rb
130
129
  - lib/libis/workflow/base/file_item.rb
131
130
  - lib/libis/workflow/base/job.rb
132
- - lib/libis/workflow/base/logger.rb
133
131
  - lib/libis/workflow/base/logging.rb
134
132
  - lib/libis/workflow/base/run.rb
135
133
  - lib/libis/workflow/base/work_item.rb
@@ -194,3 +192,4 @@ test_files:
194
192
  - spec/tasks/checksum_tester.rb
195
193
  - spec/tasks/collect_files.rb
196
194
  - spec/workflow_spec.rb
195
+ has_rdoc:
@@ -1,30 +0,0 @@
1
- require 'libis/tools/logger'
2
-
3
- module Libis
4
- module Workflow
5
- module Base
6
- module Logger
7
- include ::Libis::Tools::Logger
8
-
9
- def message(severity, msg, *args)
10
- item = self.workitem
11
- item = args.shift if args.size > 0 and args[0].is_a?(WorkItem)
12
-
13
- item.log_message(severity, to_msg(msg), *args) if item
14
- end
15
-
16
- def to_msg(msg)
17
- case msg
18
- when String
19
- {text: msg}
20
- when Integer
21
- {id: msg}
22
- else
23
- {text: (msg.to_s rescue '')}
24
- end.merge task: self.namepath
25
- end
26
-
27
- end
28
- end
29
- end
30
- end
@@ -1,7 +0,0 @@
1
- require_relative 'base/logger'
2
- require_relative 'base/logging'
3
- require_relative 'base/work_item'
4
- require_relative 'base/file_item'
5
- require_relative 'base/dir_item'
6
- require_relative 'base/run'
7
- require_relative 'base/workflow'