bitgirder-platform 0.1.25 → 0.1.27

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.
data/bin/install-mysql CHANGED
@@ -27,6 +27,12 @@ class App < BitGirderClass
27
27
  bg_attr :skip_install, processor: :boolean, default: false
28
28
  bg_attr :skip_init_db, processor: :boolean, default: false
29
29
 
30
+ bg_attr :max_start_wait,
31
+ processor: :integer,
32
+ validation: :positive,
33
+ required: false,
34
+ default: 30
35
+
30
36
  bg_attr :port, processor: :integer, validation: :positive
31
37
 
32
38
  bg_attr :root_pass
@@ -154,25 +160,14 @@ class App < BitGirderClass
154
160
  end
155
161
 
156
162
  private
157
- def await_sock( tries_remain = 3, stall = 2 )
163
+ def await_start
158
164
 
159
- code( "Attempting connect to #@port" )
160
-
161
- begin
162
- TCPSocket.new( LOCALHOST, @port ).close
163
- code( "Connected" )
164
-
165
- rescue Errno::ECONNREFUSED => e
166
-
167
- if tries_remain > 0
168
-
169
- code( "No connection, will retry in #{stall}s" )
170
- sleep( stall )
171
- await_sock( tries_remain - 1, stall * 2 )
172
- else
173
- raise "Could not connect to #@port"
174
- end
175
- end
165
+ opts = { max_wait: @max_start_wait, seed: 1 }
166
+
167
+ WaitCondition.wait_backoff( opts ) do
168
+ code( "Attempting connect to #@port" )
169
+ can_connect?( @port )
170
+ end or raise "Could not connect to mysqld at :#@port"
176
171
  end
177
172
 
178
173
  private
@@ -254,7 +249,7 @@ class App < BitGirderClass
254
249
  code( "Started mysqld as #{pid}" )
255
250
 
256
251
  begin
257
- await_sock
252
+ await_start
258
253
  run_db_init
259
254
  init_done = true
260
255
  ensure
@@ -1322,20 +1322,35 @@ class WaitCondition < BitGirderClass
1322
1322
 
1323
1323
  private_class_method :new
1324
1324
 
1325
- def initialize( f, waiter, max_tries )
1325
+ def initialize( f, waiter, opts )
1326
1326
 
1327
1327
  @f, @waiter = f, waiter
1328
- @max_tries = positive( max_tries, :max_tries )
1328
+
1329
+ raise "One of :max_tries or :max_wait must be given" unless
1330
+ opts.key?( :max_tries ) || opts.key?( :max_wait )
1331
+
1332
+ @max_tries = opts.key?( :max_tries ) ?
1333
+ positive( opts[ :max_tries ] ) : 1 << 63
1334
+
1335
+ @max_wait = opts.key?( :max_wait ) ?
1336
+ positive( opts[ :max_wait ] ) : Float::INFINITY
1329
1337
  end
1330
1338
 
1331
1339
  public
1332
1340
  def execute
1333
1341
 
1334
1342
  res = nil
1343
+
1344
+ start = Time.now
1335
1345
 
1336
1346
  @max_tries.times do |i|
1347
+
1337
1348
  break if res = @f.call
1338
- @waiter.call if i < @max_tries - 1
1349
+
1350
+ remain = @max_wait - ( Time.now - start )
1351
+ break if remain <= 0
1352
+
1353
+ @waiter.call( remain ) if i < @max_tries - 1
1339
1354
  end
1340
1355
 
1341
1356
  res
@@ -1344,15 +1359,14 @@ class WaitCondition < BitGirderClass
1344
1359
  def self.create_and_exec( waiter, opts, blk )
1345
1360
 
1346
1361
  raise "No block given" unless blk
1347
- max_tries = has_key( opts, :max_tries )
1348
1362
 
1349
- self.send( :new, blk, waiter, max_tries ).execute
1363
+ self.send( :new, blk, waiter, opts ).execute
1350
1364
  end
1351
1365
 
1352
1366
  def self.wait_poll( opts, &blk )
1353
1367
 
1354
1368
  poll = positive( has_key( opts, :poll ), :poll )
1355
- waiter = lambda { sleep( poll ) }
1369
+ waiter = lambda { |rem| sleep( [ poll, rem ].min ) }
1356
1370
 
1357
1371
  self.create_and_exec( waiter, opts, blk )
1358
1372
  end
@@ -1360,7 +1374,7 @@ class WaitCondition < BitGirderClass
1360
1374
  def self.wait_backoff( opts, &blk )
1361
1375
 
1362
1376
  seed = positive( has_key( opts, :seed ), :seed )
1363
- waiter = lambda { sleep( seed ); seed *= 2 }
1377
+ waiter = lambda { |rem| sleep( [ seed, rem ].min ); seed *= 2 }
1364
1378
 
1365
1379
  self.create_and_exec( waiter, opts, blk )
1366
1380
  end
data/lib/doc-gen18.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # Autogenerated docs on 2013-05-05 11:22:57 -0700
2
+ # Autogenerated docs on 2013-09-12 12:29:09 -0700
3
3
  #
4
4
 
5
5
  # This code is only included for rdoc purposes and would not normally get
data/lib/doc-gen20.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # Autogenerated docs on 2013-05-05 11:22:57 -0700
2
+ # Autogenerated docs on 2013-09-12 12:29:09 -0700
3
3
  #
4
4
 
5
5
  # This code is only included for rdoc purposes and would not normally get
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitgirder-platform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.25
4
+ version: 0.1.27
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-05 00:00:00.000000000 Z
12
+ date: 2013-09-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Contains core classes and interfaces for building event logger implementations.
15
15
  Also includes helper classes for incorporating assertions about event logging into