rbbt-util 5.13.18 → 5.13.19

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: 468bb74218bd754474c86120f4322048a844d6cb
4
- data.tar.gz: e2f81d8ae83485413bbf0ef009282312af0c56af
3
+ metadata.gz: 9b571306a9f5980baaa8c5d13939442178440a9e
4
+ data.tar.gz: de34e0b79dc8e1736732e64d42af40d17f2ad53f
5
5
  SHA512:
6
- metadata.gz: ef623e67afb2edf24e1762261b7ad70defda036bbdd14410ed259d3adf83ae1d06fcdc28213c16919f479579831bdce885f847fafa7b2ba145ea7a4a475a1dc8
7
- data.tar.gz: 0f10eb307be2106eea7ab3720398c72f739c144982573e84fe86633c3739182a3f37525bc7f9e969374ce7ec2d9779c34dbc29fc26f2e287b8f9f21123d73b70
6
+ metadata.gz: 6e13708123ad0a40e9bc2dfc99cbdc6c67959f2a39aa5f8c5ac512cd933775374f1195f3d5b7a127787c4eafbf99bd18bd248b296957ae28974d51041563f5a5
7
+ data.tar.gz: 034c6c8e537be9f35f8c5630f2dd40810747bdda97126303f7737adc2d7cec2d7e2e19c31568f64caf0bddffaabc6762c32fdbdfaca8bb2eebb05210bf31e891
@@ -3,7 +3,7 @@ require 'tokyocabinet'
3
3
  module Persist
4
4
 
5
5
  module TCAdapter
6
- attr_accessor :persistence_path, :tokyocabinet_class, :closed, :writable
6
+ attr_accessor :persistence_path, :tokyocabinet_class, :closed, :writable, :mutex
7
7
 
8
8
  def self.open(path, write, tokyocabinet_class = TokyoCabinet::HDB)
9
9
  tokyocabinet_class = TokyoCabinet::HDB if tokyocabinet_class == "HDB"
@@ -23,6 +23,7 @@ module Persist
23
23
  database.persistence_path ||= path
24
24
  database.tokyocabinet_class = tokyocabinet_class
25
25
 
26
+ database.mutex = Mutex.new
26
27
  database
27
28
  end
28
29
 
@@ -76,6 +77,9 @@ module Persist
76
77
  @writable
77
78
  end
78
79
 
80
+ def read?
81
+ ! write?
82
+ end
79
83
  #def each
80
84
  # iterinit
81
85
  # while key = iternext
@@ -102,20 +106,36 @@ module Persist
102
106
  def write_and_read
103
107
  lock_filename = Persist.persistence_path(persistence_path + '.write', {:dir => TSV.lock_dir})
104
108
  Misc.lock(lock_filename) do
105
- write if @closed or not write?
106
- res = begin
107
- yield
108
- ensure
109
- read
110
- end
111
- res
109
+ @mutex.synchronize do
110
+ write if @closed or not write?
111
+ res = begin
112
+ yield
113
+ ensure
114
+ read
115
+ end
116
+ res
117
+ end
112
118
  end
113
119
  end
114
120
 
115
121
  def write_and_close
116
122
  lock_filename = Persist.persistence_path(persistence_path + '.write', {:dir => TSV.lock_dir})
117
123
  Misc.lock(lock_filename) do
118
- write if @closed or not write?
124
+ @mutex.synchronize do
125
+ write if @closed or not write?
126
+ res = begin
127
+ yield
128
+ ensure
129
+ close
130
+ end
131
+ res
132
+ end
133
+ end
134
+ end
135
+
136
+ def read_and_close
137
+ @mutex.synchronize do
138
+ read if @closed or not read?
119
139
  res = begin
120
140
  yield
121
141
  ensure
@@ -125,15 +145,6 @@ module Persist
125
145
  end
126
146
  end
127
147
 
128
- def read_and_close
129
- read if @closed or write?
130
- res = begin
131
- yield
132
- ensure
133
- close
134
- end
135
- res
136
- end
137
148
 
138
149
  def merge!(hash)
139
150
  hash.each do |key,values|
data/lib/rbbt/persist.rb CHANGED
@@ -289,15 +289,15 @@ module Persist
289
289
  res = tee_stream(res, path, type, res.respond_to?(:callback)? res.callback : nil, res.respond_to?(:abort_callback)? res.abort_callback : nil)
290
290
  ConcurrentStream.setup res do
291
291
  begin
292
- lockfile.unlock if File.exists? lockfile.path and lockfile.locked?
293
- rescue
292
+ lockfile.unlock #if File.exists? lockfile.path and lockfile.locked?
293
+ rescue Exception
294
294
  Log.medium "Lockfile exception: " << $!.message
295
295
  end
296
296
  end
297
297
  res.abort_callback = Proc.new do
298
298
  begin
299
- lockfile.unlock if File.exists? lockfile.path and lockfile.locked?
300
- rescue
299
+ lockfile.unlock #if File.exists? lockfile.path and lockfile.locked?
300
+ rescue Exception
301
301
  Log.medium "Lockfile exception: " << $!.message
302
302
  end
303
303
  end
@@ -308,16 +308,16 @@ module Persist
308
308
  ConcurrentStream.setup res do
309
309
  begin
310
310
  stream.callback
311
- lockfile.unlock if File.exists? lockfile.path and lockfile.locked?
312
- rescue
311
+ lockfile.unlock #if File.exists? lockfile.path and lockfile.locked?
312
+ rescue Exception
313
313
  Log.medium "Lockfile exception: " << $!.message
314
314
  end
315
315
  end
316
316
  res.abort_callback = Proc.new do
317
317
  begin
318
318
  stream.abort
319
- lockfile.unlock if File.exists? lockfile.path and lockfile.locked?
320
- rescue
319
+ lockfile.unlock #if File.exists? lockfile.path and lockfile.locked?
320
+ rescue Exception
321
321
  Log.medium "Lockfile exception: " << $!.message
322
322
  end
323
323
  end
data/lib/rbbt/util/R.rb CHANGED
@@ -101,6 +101,7 @@ if (! is.null(data)){ rbbt.tsv.write('#{f}', data); }
101
101
  else
102
102
  tsv = TSV.open(f, open_options) unless open_options[:ignore_output]
103
103
  tsv.key_field = open_options[:key] if open_options.include? :key
104
+ tsv.namespace ||= self.namespace if self.namespace
104
105
  tsv
105
106
  end
106
107
  end
@@ -20,7 +20,7 @@ class RbbtProcessQueue
20
20
  def clean
21
21
  @sread.close unless @sread.closed?
22
22
  @swrite.close unless @swrite.closed?
23
- Log.warn "Destroying socket semaphores: #{key}"
23
+ Log.warn "Destroying socket semaphores"
24
24
  RbbtSemaphore.delete_semaphore(@write_sem)
25
25
  RbbtSemaphore.delete_semaphore(@read_sem)
26
26
  end
@@ -34,7 +34,7 @@ module Log
34
34
  @history ||= []
35
35
  else
36
36
  @history << thr
37
- @history.shift if @history.length > 10
37
+ @history.shift if @history.length > 20
38
38
  end
39
39
 
40
40
  @mean_max ||= 0
data/lib/rbbt/util/log.rb CHANGED
@@ -32,7 +32,9 @@ module Log
32
32
  class << self
33
33
  attr_accessor :logfile, :severity, :nocolor, :tty_size
34
34
  end
35
+
35
36
  self.nocolor = ENV["RBBT_NOCOLOR"] == 'true'
37
+
36
38
  require "highline/system_extensions.rb"
37
39
  self.tty_size = HighLine::SystemExtensions.terminal_size.first
38
40
 
@@ -205,7 +207,7 @@ def ppp(message)
205
207
  stack = caller
206
208
  puts "#{Log.color :cyan, "PRINT:"} " << stack.first
207
209
  puts ""
208
- puts "=> " << message
210
+ puts Log.color(:cyan, "=> ") << message
209
211
  puts ""
210
212
  end
211
213
 
@@ -1,4 +1,4 @@
1
- Lockfile.refresh = false if ENV["RBBT_NO_LOCKFILE_REFRESH"] == "true"
1
+ Lockfile.refresh = false #if ENV["RBBT_NO_LOCKFILE_REFRESH"] == "true"
2
2
 
3
3
  module Misc
4
4
 
@@ -23,6 +23,7 @@ module Misc
23
23
 
24
24
  if hostname == info["host"] and not Misc.pid_exists?(info["pid"])
25
25
  Log.high("Removing lockfile: #{lock_path}. This pid #{Process.pid}. Content: #{info.inspect}")
26
+
26
27
  FileUtils.rm lock_path
27
28
  end
28
29
  end
@@ -48,7 +49,10 @@ module Misc
48
49
  raise $!
49
50
  ensure
50
51
  if unlock
51
- lockfile.unlock if lockfile.locked?
52
+ begin
53
+ lockfile.unlock #if lockfile.locked?
54
+ rescue Exception
55
+ end
52
56
  end
53
57
  end
54
58
 
@@ -146,20 +146,21 @@ module Open
146
146
  def self.get_stream_from_repo(dir, sub_path)
147
147
  repo = get_repo_from_dir(dir)
148
148
  repo.read_and_close do
149
- StringIO.new repo[sub_path]
149
+ text = repo[sub_path]
150
+ text.nil? ? nil : StringIO.new(text)
150
151
  end
151
152
  end
152
153
 
153
154
  def self.save_content_in_repo(dir, sub_path, content)
154
155
  repo = get_repo_from_dir(dir)
155
- repo.write_and_close do
156
+ repo.write_and_read do
156
157
  repo[sub_path] = content
157
158
  end
158
159
  end
159
160
 
160
161
  def self.remove_from_repo(dir, sub_path, recursive = false)
161
162
  repo = get_repo_from_dir(dir)
162
- repo.write_and_close do
163
+ repo.write_and_read do
163
164
  if recursive
164
165
  repo.outlist repo.range sub_path, true, sub_path.sub(/.$/,('\1'.ord + 1).chr), false
165
166
  else
@@ -171,7 +172,7 @@ module Open
171
172
  def self.exists_in_repo(dir, sub_path, content)
172
173
  repo = get_repo_from_dir(dir)
173
174
  repo.read_and_close do
174
- repo.include? sub_path
175
+ repo.include? sub_path
175
176
  end
176
177
  end
177
178
 
@@ -61,8 +61,12 @@ void post_semaphore(char* name){
61
61
  end
62
62
 
63
63
  def self.with_semaphore(size, file = nil)
64
- file = "/" << Misc.digest(rand(1000000000000).to_s) if file.nil?
65
- file.gsub!('/', '_')
64
+ if file.nil?
65
+ file = "/" << Misc.digest(rand(1000000000000).to_s) if file.nil?
66
+ else
67
+ file = file.gsub('/', '_') if file
68
+ end
69
+
66
70
  begin
67
71
  Log.warn "Creating semaphore (#{ size }): #{file}"
68
72
  RbbtSemaphore.create_semaphore(file, size)
@@ -432,7 +432,7 @@ class Step
432
432
  end
433
433
 
434
434
  def grace
435
- until done? or result or streaming? or error? or aborted?
435
+ until done? or result or error? or aborted? or streaming?
436
436
  sleep 1
437
437
  end
438
438
  self
@@ -10,7 +10,6 @@ class TestRbbtSemaphore < Test::Unit::TestCase
10
10
  100.times do
11
11
  RbbtSemaphore.wait_semaphore(s)
12
12
  sleep 0.001
13
- puts '.'
14
13
  RbbtSemaphore.post_semaphore(s)
15
14
  end
16
15
  end
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.18
4
+ version: 5.13.19
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-05-22 00:00:00.000000000 Z
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake