bosh_common 1.2641.0 → 1.2652.0

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: 4d28e22d3c46e0a9b7b28d6fe6dca3ee4049621a
4
- data.tar.gz: 10c2112afe5201e39a4e02d7a3d6e2e93649500b
3
+ metadata.gz: 9a699a5bce247048d9a803c1ab8268b40e787871
4
+ data.tar.gz: 88d8d7150bc04ec1a18d1b90ebe2fabc2d4c0025
5
5
  SHA512:
6
- metadata.gz: cebb007e17d2d841fccb9ed2ea8a89bf2e2cacaa9a4c6cc799763063dd45d397091086b1d1d3d52962f8a036df66eeb6431a037840142a0da8f2663eaa5f3e02
7
- data.tar.gz: 7cd9dd1f6ca657c4e3601998089a0cb2945be79fcd3a4e1a4221925ef3890699b2bc099b0d84277f3a0af1e7397f348e007eb0ef8558655707c75d33d8db4d49
6
+ metadata.gz: f52497b5219a4ddfffb91880fd5d533bc5f23a9fdf6db76697e85272c33ad889484c746d65fdfd094c76ff79ae2a086e0fe9b7b96d39d36ca47fcd4985bb302f
7
+ data.tar.gz: 8871fbec389398907aeda81d0e9a2d7a2bc4d165483d3d2ef3d6917e018ce9722123154c64f3cd5aafec5b755c5658d5ff880e0a8e05640fe216f221d9e564c5
@@ -7,24 +7,32 @@ module Bosh
7
7
 
8
8
  @ensure_callback = opts[:ensure]
9
9
  @matching = opts[:matching]
10
- @on_exception = [opts[:on]].flatten
11
10
  @try_count = 0
12
11
  @retry_exception = nil
13
12
  @retry_limit = opts[:tries]
14
13
  @sleeper = opts[:sleep]
14
+
15
+ @matchers = Array(opts[:on]).map do |klass_or_matcher|
16
+ if klass_or_matcher.is_a?(Class)
17
+ ErrorMatcher.by_class(klass_or_matcher)
18
+ else
19
+ klass_or_matcher
20
+ end
21
+ end
15
22
  end
16
23
 
17
- # this method will loop until the block returns a true value
18
- def retryer(&block)
24
+ # Loops until the block returns a true value
25
+ def retryer(&blk)
19
26
  loop do
20
27
  @try_count += 1
21
- y = yield @try_count, @retry_exception
22
- @retry_exception = nil # no exception was raised in the block
28
+ y = blk.call(@try_count, @retry_exception)
29
+ @retry_exception = nil # no exception was raised in the block
23
30
  return y if y
24
31
  raise Bosh::Common::RetryCountExceeded if @try_count >= @retry_limit
25
32
  wait
26
33
  end
27
- rescue *@on_exception => exception
34
+ rescue Exception => exception
35
+ raise unless @matchers.any? { |m| m.matches?(exception) }
28
36
  raise unless exception.message =~ @matching
29
37
  raise if @try_count >= @retry_limit
30
38
 
@@ -41,7 +49,6 @@ module Bosh
41
49
  merged_options = default_options.merge(options)
42
50
  invalid_options = merged_options.keys - default_options.keys
43
51
  raise ArgumentError.new("Invalid options: #{invalid_options.join(", ")}") unless invalid_options.empty?
44
-
45
52
  merged_options
46
53
  end
47
54
 
@@ -51,13 +58,14 @@ module Bosh
51
58
  sleep: exponential_sleeper,
52
59
  on: [],
53
60
  matching: /.*/,
54
- ensure: Proc.new {}
61
+ ensure: Proc.new {},
55
62
  }
56
63
  end
57
64
 
58
65
  def wait
59
66
  sleep(@sleeper.respond_to?(:call) ? @sleeper.call(@try_count, @retry_exception) : @sleeper)
60
- rescue *@on_exception
67
+ rescue Exception => exception
68
+ raise unless @matchers.any? { |m| m.matches?(exception) }
61
69
  # SignalException could be raised while sleeping, so if you want to catch it,
62
70
  # it need to be passed in the list of exceptions to ignore
63
71
  end
@@ -69,6 +77,20 @@ module Bosh
69
77
  def sleep(*args, &blk)
70
78
  Kernel.sleep(*args, &blk)
71
79
  end
80
+
81
+ class ErrorMatcher
82
+ def self.by_class(klass)
83
+ new(klass, /.*/)
84
+ end
85
+
86
+ def initialize(klass, message_regex)
87
+ @klass = klass
88
+ @message_regex = message_regex
89
+ end
90
+
91
+ def matches?(error)
92
+ !!(error.kind_of?(@klass) && error.message =~ @message_regex)
93
+ end
94
+ end
72
95
  end
73
96
  end
74
-
@@ -1,4 +1,4 @@
1
- require "logger"
1
+ require 'logger'
2
2
 
3
3
  module Bosh
4
4
  class ThreadPool
@@ -45,14 +45,14 @@ module Bosh
45
45
  @actions << block
46
46
  if @state == :open
47
47
  if @available_threads > 0
48
- @logger.debug("Creating new thread")
48
+ @logger.debug('Creating new thread')
49
49
  @available_threads -= 1
50
50
  create_thread
51
51
  else
52
- @logger.debug("All threads are currently busy, queuing action")
52
+ @logger.debug('All threads are currently busy, queuing action')
53
53
  end
54
54
  elsif @state == :paused
55
- @logger.debug("Pool is paused, queueing action.")
55
+ @logger.debug('Pool is paused, queueing action')
56
56
  end
57
57
  end
58
58
  end
@@ -64,10 +64,8 @@ module Bosh
64
64
  action = nil
65
65
  @lock.synchronize do
66
66
  action = @actions.shift unless @boom
67
- if action
68
- @logger.debug("Found an action that needs to be processed")
69
- else
70
- @logger.debug("Thread is no longer needed, cleaning up")
67
+ unless action
68
+ @logger.debug('Thread is no longer needed, cleaning up')
71
69
  @available_threads += 1
72
70
  @threads.delete(thread) if @state == :open
73
71
  end
@@ -103,7 +101,7 @@ module Bosh
103
101
  end
104
102
 
105
103
  def wait
106
- @logger.debug("Waiting for tasks to complete")
104
+ @logger.debug('Waiting for tasks to complete')
107
105
  @lock.synchronize do
108
106
  @cv.wait(@lock) while working?
109
107
  raise @boom if @boom
@@ -112,7 +110,7 @@ module Bosh
112
110
 
113
111
  def shutdown
114
112
  return if @state == :closed
115
- @logger.debug("Shutting down pool")
113
+ @logger.debug('Shutting down pool')
116
114
  @lock.synchronize do
117
115
  return if @state == :closed
118
116
  @state = :closed
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Common
3
- VERSION = '1.2641.0'
3
+ VERSION = '1.2652.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh_common
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2641.0
4
+ version: 1.2652.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - VMware
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-11 00:00:00.000000000 Z
11
+ date: 2014-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: semi_semantic
@@ -26,7 +26,7 @@ dependencies:
26
26
  version: 1.1.0
27
27
  description: |-
28
28
  BOSH common
29
- 23fe6f
29
+ 43d2e8
30
30
  email: support@cloudfoundry.com
31
31
  executables: []
32
32
  extensions: []