rbbt-util 5.13.3 → 5.13.4

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: 715d410e93dddd02e14dd6d04f31917470c10b3d
4
- data.tar.gz: 473271c8efe67c3465b204078d228618bedbc327
3
+ metadata.gz: 43ee6ce8a12a65ea0a42e62a3eef0a917c084051
4
+ data.tar.gz: 91fc982769f590d4f33738c87c459afeaa5dd7be
5
5
  SHA512:
6
- metadata.gz: 3412998c1d2dce774a3d3a6a41428ab4506a6de2480b73be70890ae97d62be4285d1854881f6af92a551098c93e7b2dc62aaa8867a199e9ad26b3d991a213667
7
- data.tar.gz: fb333f016809936f1ab2a928934683a3759a16d5ff3238e088535a7802f62566a732bfc7e7b0e3a7d638ebaa978b6dad6856ef2f3d5795f068213c5c14751e3a
6
+ metadata.gz: 18a0478c57dd34188715d0eede18d661739f862dcc40a303383254638a93c73ae4a2bf294bcfdf2d5480f895321a8c94eafdcecf0b1a2cbcddd510103ed8311c
7
+ data.tar.gz: 3a3e30b11a53ea72d7b76065a646a05faec9607c53046f69db78842be35072208e23b235121fe9e909646031b45ddcff4d6f4874e1158cb0b4f30367173868f1
data/bin/rbbt CHANGED
@@ -13,6 +13,7 @@ $ rbbt <command> <subcommand> ... -a --arg1 --arg2='value' --arg3 'another-value
13
13
  -cd--command_dir* #{Log.color :yellow, "Directory from where to load command scripts"}
14
14
  --profile #{Log.color :yellow, "Profile execution"}
15
15
  --nocolor #{Log.color :yellow, "Disable colored output"}
16
+ --nobar #{Log.color :yellow, "Disable progress report"}
16
17
  --locate_file #{Log.color :yellow, "Report the location of the script instead of executing it"}
17
18
  EOF
18
19
 
@@ -20,6 +21,10 @@ if options[:nocolor]
20
21
  Log.nocolor = true
21
22
  end
22
23
 
24
+ if options.delete :nobar
25
+ ENV["RBBT_NO_PROGRESS"] = "true"
26
+ end
27
+
23
28
  locate = options.delete :locate_file
24
29
 
25
30
  if options[:log]
data/lib/rbbt/persist.rb CHANGED
@@ -190,7 +190,7 @@ module Persist
190
190
  end
191
191
  end
192
192
 
193
- def self.tee_stream_thread(stream, path, type, callback = nil)
193
+ def self.tee_stream_thread(stream, path, type, callback = nil, abort_callback = nil)
194
194
  file, out = Misc.tee_stream(stream)
195
195
 
196
196
  saver_thread = Thread.new(Thread.current) do |parent|
@@ -209,9 +209,12 @@ module Persist
209
209
  end
210
210
  end
211
211
  ConcurrentStream.setup(out, :threads => saver_thread, :filename => path)
212
+ out.callback = callback
213
+ out.abort_callback = abort_callback
214
+ out
212
215
  end
213
216
 
214
- def self.tee_stream_pipe(stream, path, type, callback = nil)
217
+ def self.tee_stream_pipe(stream, path, type, callback = nil, abort_callback = nil)
215
218
  parent_pid = Process.pid
216
219
  out = Misc.open_pipe true, false do |sin|
217
220
  begin
@@ -280,12 +283,11 @@ module Persist
280
283
  if persist_options[:no_load] == :stream
281
284
  case res
282
285
  when IO
283
- res = tee_stream(res, path, type, res.respond_to?(:callback)? res.callback : nil)
286
+ res = tee_stream(res, path, type, res.respond_to?(:callback)? res.callback : nil, res.respond_to?(:abort_callback)? res.abort_callback : nil)
284
287
  ConcurrentStream.setup res do
285
288
  begin
286
289
  lockfile.unlock if File.exists? lockfile.path and lockfile.locked?
287
290
  rescue
288
- Log.exception $!
289
291
  Log.warn "Lockfile exception: " << $!.message
290
292
  end
291
293
  end
@@ -293,26 +295,26 @@ module Persist
293
295
  begin
294
296
  lockfile.unlock if File.exists? lockfile.path and lockfile.locked?
295
297
  rescue
296
- Log.exception $!
297
298
  Log.warn "Lockfile exception: " << $!.message
298
299
  end
299
300
  end
300
301
  raise KeepLocked.new res
301
302
  when TSV::Dumper
302
- res = tee_stream(res.stream, path, type, res.respond_to?(:callback)? res.callback : nil)
303
+ stream = res.stream
304
+ res = tee_stream(stream, path, type)
303
305
  ConcurrentStream.setup res do
304
306
  begin
307
+ stream.callback
305
308
  lockfile.unlock if File.exists? lockfile.path and lockfile.locked?
306
309
  rescue
307
- Log.exception $!
308
310
  Log.warn "Lockfile exception: " << $!.message
309
311
  end
310
312
  end
311
313
  res.abort_callback = Proc.new do
312
314
  begin
315
+ stream.abort
313
316
  lockfile.unlock if File.exists? lockfile.path and lockfile.locked?
314
317
  rescue
315
- Log.exception $!
316
318
  Log.warn "Lockfile exception: " << $!.message
317
319
  end
318
320
  end
@@ -1,6 +1,8 @@
1
1
  module TSV
2
2
  def self.obj_stream(obj)
3
3
  case obj
4
+ when Step
5
+ obj.result
4
6
  when IO, File
5
7
  obj
6
8
  when TSV::Dumper
@@ -252,6 +254,7 @@ module TSV
252
254
  stream.abort if stream and stream.respond_to? :abort
253
255
  stream = obj_stream(options[:into])
254
256
  stream.abort if stream.respond_to? :abort
257
+ Log.warn "Aborted traversing 2 #{stream_name(obj)}"
255
258
  rescue Exception
256
259
  Log.warn "Exception traversing #{stream_name(obj)}"
257
260
  stream = obj_stream(obj)
@@ -359,7 +362,6 @@ module TSV
359
362
  rescue Exception
360
363
  stream = obj_stream(store)
361
364
  stream.abort if stream.respond_to? :abort
362
- Log.exception $!
363
365
  raise $!
364
366
  end
365
367
  end
@@ -423,7 +425,7 @@ module TSV
423
425
  begin
424
426
  traverse_run(obj, threads, cpus, options, &block)
425
427
  into.close if into.respond_to? :close
426
- rescue
428
+ rescue Exception
427
429
  stream = obj_stream(obj)
428
430
  stream.abort if stream and stream.respond_to? :abort
429
431
  stream = obj_stream(into)
@@ -483,9 +485,17 @@ module TSV
483
485
  store_into into, e
484
486
  rescue Aborted
485
487
  Log.warn "Aborted callback #{stream_name(obj)} #{Log.color :green, "->"} #{stream_name(options[:into])}"
488
+ stream = nil
489
+ stream = get_stream obj
490
+ stream.abort if stream.respond_to? :abort
491
+ raise $!
486
492
  rescue Exception
487
493
  Log.warn "Exception callback #{stream_name(obj)} #{Log.color :green, "->"} #{stream_name(options[:into])}"
488
494
  Log.exception $!
495
+ stream = nil
496
+ stream = get_stream obj
497
+ stream.abort if stream.respond_to? :abort
498
+ raise $!
489
499
  ensure
490
500
  bar.tick if bar
491
501
  end
@@ -149,11 +149,12 @@ module TSV
149
149
  stream.join if stream.respond_to? :join
150
150
  end
151
151
  rescue Exception
152
- streams.each do |stream|
152
+ ts = streams.collect do |stream|
153
153
  Thread.new do
154
154
  stream.abort if stream.respond_to? :abort
155
155
  end
156
156
  end
157
+ ts.each do |t| t.join end
157
158
  raise $!
158
159
  end
159
160
  end
@@ -25,6 +25,7 @@ module Log
25
25
 
26
26
  # Used to register a new completed loop iteration.
27
27
  def tick(step = nil)
28
+ return if ENV["RBBT_NO_PROGRESS"] == 'true'
28
29
 
29
30
  if step.nil?
30
31
  @current += 1
@@ -163,6 +164,8 @@ module Log
163
164
  Log::LAST.replace "progress"
164
165
  length = Log::ProgressBar.cleanup_bars
165
166
  length.times{print(io, "\n")}
167
+ else
168
+ print(io, "\n") if @last_report == -1
166
169
  end
167
170
  print(io, up_lines(@depth) << report_msg << down_lines(@depth)) if severity >= Log.severity
168
171
  @last_report = Time.now if @last_report == -1
@@ -173,6 +176,8 @@ module Log
173
176
  Log::LAST.replace "progress"
174
177
  length = Log::ProgressBar.cleanup_bars
175
178
  length.times{print(io, "\n")}
179
+ else
180
+ print(io, "\n") if @last_report == -1
176
181
  end
177
182
  print(io, up_lines(@depth) << throughput_msg << down_lines(@depth)) if severity >= Log.severity
178
183
  @last_report = Time.now
@@ -217,10 +222,9 @@ module Log
217
222
  end
218
223
 
219
224
  def self.remove_bar(bar)
220
- bar.done unless bar.max
225
+ bar.done unless bar.max or ENV["RBBT_NO_PROGRESS"] == 'true'
221
226
  BAR_MUTEX.synchronize do
222
227
  REMOVE << bar
223
- Log::LAST.replace "remove"
224
228
  end
225
229
  end
226
230
 
@@ -98,18 +98,21 @@ module ConcurrentStream
98
98
 
99
99
  def abort_pids
100
100
  @pids.each{|pid| Process.kill :INT, pid } if @pids
101
+ @pids = []
101
102
  end
102
103
 
103
104
  def abort
105
+ Log.warn "Aborting stream #{Misc.fingerprint self} -- #{@abort_callback} [#{@aborted}]"
104
106
  return if @aborted
107
+ @aborted = true
105
108
  begin
106
- abort_threads
107
- abort_pids
109
+ @callback = nil
108
110
  @abort_callback.call if @abort_callback
109
- ensure
110
111
  @abort_callback = nil
111
- @callback = nil
112
- @aborted = true
112
+ close unless closed?
113
+
114
+ abort_threads
115
+ abort_pids
113
116
  end
114
117
  end
115
118
 
@@ -49,7 +49,6 @@ module Misc
49
49
  ensure
50
50
  if unlock
51
51
  lockfile.unlock if lockfile.locked?
52
- FileUtils.rm lock_path if File.exists? lock_path
53
52
  end
54
53
  end
55
54
 
@@ -7,7 +7,7 @@ module Misc
7
7
 
8
8
  dup_array = options.delete :dup_array
9
9
 
10
- if Annotated === field or Entity.respond_to?(:formats) and Entity.formats.include? field
10
+ if Annotated === field or (Entity.respond_to?(:formats) and Entity.formats.include? field)
11
11
  params = options.dup
12
12
 
13
13
  params[:format] ||= params.delete "format"
@@ -100,20 +100,26 @@ module Misc
100
100
  stream_in2.close unless stream_in2.closed?
101
101
  stream.join if stream.respond_to? :join
102
102
  rescue Aborted, Interrupt
103
- begin
104
- stream.abort if stream.respond_to? :abort
105
- rescue
106
- Log.exception $!
107
- end
103
+ Log.warn "Tee aborting #{Misc.fingerprint stream}"
104
+ stream.abort if stream.respond_to? :abort
105
+ stream_out1.abort if stream_out1.respond_to? :abort
106
+ stream_out2.abort if stream_out2.respond_to? :abort
107
+ parent.raise $!
108
108
  rescue Exception
109
- Log.exception $!
110
109
  stream.abort if stream.respond_to? :abort
110
+ parent.raise $!
111
111
  end
112
112
  end
113
113
 
114
114
  ConcurrentStream.setup stream_out1, :threads => splitter_thread
115
115
  ConcurrentStream.setup stream_out2, :threads => splitter_thread
116
116
 
117
+ stream_out1.callback = stream.callback if stream.respond_to? :callback
118
+ stream_out1.abort_callback = stream.abort_callback if stream.respond_to? :abort_callback
119
+
120
+ stream_out2.callback = stream.callback if stream.respond_to? :callback
121
+ stream_out2.abort_callback = stream.abort_callback if stream.respond_to? :abort_callback
122
+
117
123
  [stream_out1, stream_out2]
118
124
  end
119
125
 
data/lib/rbbt/workflow.rb CHANGED
@@ -188,7 +188,6 @@ module Workflow
188
188
  def step_cache
189
189
  @step_cache ||= Workflow::STEP_CACHE
190
190
  end
191
-
192
191
 
193
192
  def helpers
194
193
  @helpers ||= {}
@@ -237,6 +236,7 @@ module Workflow
237
236
  def get_job_step(step_path, task = nil, input_values = nil, dependencies = nil)
238
237
  step_path = step_path.call if Proc === step_path
239
238
  persist = input_values.nil? ? false : true
239
+ #persist = false
240
240
  key = Path === step_path ? step_path.find : step_path
241
241
  step = Persist.memory("Step", :key => key, :repo => step_cache, :persist => persist) do
242
242
  step = Step.new step_path, task, input_values, dependencies
@@ -217,7 +217,7 @@ class Step
217
217
  end
218
218
 
219
219
  def aborted?
220
- info[:status] == :aborted
220
+ @aborted || info[:status] == :aborted
221
221
  end
222
222
 
223
223
  # {{{ INFO
@@ -8,7 +8,7 @@ class Step
8
8
  attr_accessor :path, :task, :inputs, :dependencies, :bindings
9
9
  attr_accessor :pid
10
10
  attr_accessor :exec
11
- attr_accessor :result, :mutex
11
+ attr_accessor :result, :mutex, :seen
12
12
 
13
13
  class << self
14
14
  attr_accessor :lock_dir
@@ -66,13 +66,12 @@ class Step
66
66
  def get_stream
67
67
  @mutex.synchronize do
68
68
  begin
69
+ return nil if @saved_stream
69
70
  if IO === @result
70
71
  @saved_stream = @result
71
72
  else
72
73
  nil
73
74
  end
74
- ensure
75
- @result = nil
76
75
  end
77
76
  end
78
77
  end
@@ -118,29 +117,33 @@ class Step
118
117
  end
119
118
  end
120
119
 
121
- def run_dependencies(seen = [])
120
+ def run_dependencies
121
+ @seen ||= []
122
122
  dependencies.uniq.each do |dependency|
123
-
124
123
  next if seen.collect{|d| d.path}.include?(dependency.path)
125
- seen << dependency
126
- seen.concat dependency.rec_dependencies.collect{|d| d }
124
+ dependency.seen = seen
125
+ @seen << dependency
126
+ @seen.concat dependency.rec_dependencies.collect{|d| d }
127
+ @seen.uniq!
127
128
  end
128
129
 
129
- seen.each do |dependency|
130
+ @seen.each do |dependency|
130
131
  next if dependency == self
132
+ next unless dependencies.include? dependency
131
133
  dependency.relay_log self
132
134
  dependency.dup_inputs
133
135
  end
134
136
 
135
- seen.each do |dependency|
137
+ @seen.each do |dependency|
136
138
  next if dependency == self
139
+ next unless dependencies.include? dependency
137
140
  Log.info "#{Log.color :magenta, "Checking dependency"} #{Log.color :yellow, task.name.to_s || ""} => #{Log.color :yellow, dependency.task_name.to_s || ""} -- #{Log.color :blue, dependency.path}"
138
141
  begin
139
142
  if dependency.streaming?
140
143
  next if dependency.running?
141
144
  dependency.clean
142
145
  else
143
- dependency.clean if not dependency.done? and (dependency.error? or dependency.aborted?)
146
+ dependency.clean if (dependency.error? or dependency.aborted? or not dependency.done?)
144
147
  end
145
148
 
146
149
  unless dependency.result or dependency.done?
@@ -155,8 +158,8 @@ class Step
155
158
  rescue Interrupt
156
159
  backtrace = $!.backtrace
157
160
  set_info :backtrace, backtrace
158
- log(:error, "Interrupted dependency #{Log.color :yellow, dependency.task.name.to_s}")
159
161
  self.abort
162
+ log(:error, "Interrupted dependency #{Log.color :yellow, dependency.task.name.to_s}")
160
163
  raise $!
161
164
  rescue Exception
162
165
  backtrace = $!.backtrace
@@ -171,8 +174,8 @@ class Step
171
174
  def run(no_load = false)
172
175
  result = nil
173
176
 
174
- @mutex.synchronize do
175
- begin
177
+ begin
178
+ @mutex.synchronize do
176
179
  no_load = no_load ? :stream : false
177
180
  result = Persist.persist "Job", @task.result_type, :file => path, :check => checks, :no_load => no_load do |lockfile|
178
181
  if Step === Step.log_relay_step and not self == Step.log_relay_step
@@ -244,8 +247,6 @@ class Step
244
247
  result.abort_callback = Proc.new do
245
248
  begin
246
249
  log :error, "#{Log.color :red, "ERROR -- streamming aborted"} #{Log.color :yellow, task.name.to_s || ""} [#{Process.pid}] -- #{path}" if status == :streaming
247
- stop_dependencies
248
- abort_stream
249
250
  rescue
250
251
  Log.exception $!
251
252
  ensure
@@ -267,9 +268,9 @@ class Step
267
268
  end
268
269
  result.stream.abort_callback = Proc.new do
269
270
  begin
270
- stop_dependencies
271
271
  log :error, "#{Log.color :red, "ERROR -- streamming aborted"} #{Log.color :yellow, task.name.to_s || ""} [#{Process.pid}] -- #{path}" if status == :streaming
272
272
  rescue Exception
273
+ Log.exception $!
273
274
  end
274
275
  end
275
276
  else
@@ -287,9 +288,10 @@ class Step
287
288
  else
288
289
  @result = prepare_result result, @task.result_description
289
290
  end
290
- rescue Exception
291
- self.abort
292
291
  end
292
+ rescue Exception
293
+ self.abort
294
+ raise $!
293
295
  end
294
296
  end
295
297
 
@@ -343,13 +345,7 @@ class Step
343
345
 
344
346
  def stop_dependencies
345
347
  dependencies.each do |dep|
346
- Log.warn "Stoping #{Misc.fingerprint dep}"
347
- begin
348
- dep.abort unless dep.done?
349
- rescue Exception
350
- Log.exception $!
351
- rescue Aborted
352
- end
348
+ dep.abort
353
349
  end
354
350
  kill_children
355
351
  end
@@ -379,11 +375,11 @@ class Step
379
375
  def abort_stream
380
376
  stream = get_stream if @result
381
377
  stream ||= @saved_stream
378
+ @saved_stream = nil
382
379
  if stream and stream.respond_to? :abort and not stream.aborted?
383
380
  begin
384
381
  Log.medium "Aborting job stream #{stream.inspect} -- #{Log.color :blue, path}"
385
382
  stream.abort
386
- Log.medium "Aborted job stream #{stream.inspect} -- #{Log.color :blue, path}"
387
383
  #stream.close unless stream.closed?
388
384
  rescue Aborted
389
385
  Log.medium "Aborting job stream #{stream.inspect} ABORTED RETRY -- #{Log.color :blue, path}"
@@ -394,19 +390,29 @@ class Step
394
390
 
395
391
  def abort
396
392
  return if @aborted
393
+ @aborted = true
394
+ return if error?
395
+ return if done?
397
396
  Log.medium{"#{Log.color :red, "Aborting"} #{Log.color :blue, path}"}
398
397
  begin
399
- stop_dependencies
400
- @aborted = true
401
398
  abort_stream
402
399
  abort_pid
400
+ stop_dependencies
403
401
  rescue Aborted
404
402
  Log.medium{"#{Log.color :red, "Aborting ABORTED RETRY"} #{Log.color :blue, path}"}
405
403
  retry
406
404
  rescue Exception
407
- Log.exception $!
405
+ retry
408
406
  ensure
409
- @aborted = true
407
+ if Open.exists? path
408
+ Log.warn "Aborted job had finished. Removing result"
409
+ begin
410
+ Open.rm path
411
+ rescue Exception
412
+ Log.warn "Exception removing result of aborted job: #{$!.message}"
413
+ end
414
+ end
415
+
410
416
  begin
411
417
  log(:aborted, "Job aborted")
412
418
  rescue Exception
@@ -302,6 +302,7 @@ begin
302
302
  end
303
303
 
304
304
  if do_fork
305
+ ENV["RBBT_NO_PROGRESS"] = "true"
305
306
  if detach
306
307
  job.fork
307
308
  Process.detach job.pid if job.pid
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.13.3
4
+ version: 5.13.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-29 00:00:00.000000000 Z
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake