sfn 3.0.28 → 3.0.30

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.
Files changed (77) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +5 -0
  3. data/docs/callbacks.md +1 -0
  4. data/lib/chef/knife/knife_plugin_seed.rb +11 -17
  5. data/lib/sfn.rb +0 -2
  6. data/lib/sfn/api_provider.rb +0 -2
  7. data/lib/sfn/api_provider/google.rb +6 -9
  8. data/lib/sfn/api_provider/terraform.rb +4 -6
  9. data/lib/sfn/cache.rb +36 -39
  10. data/lib/sfn/callback.rb +0 -2
  11. data/lib/sfn/callback/aws_assume_role.rb +7 -8
  12. data/lib/sfn/callback/aws_mfa.rb +7 -8
  13. data/lib/sfn/callback/stack_policy.rb +15 -17
  14. data/lib/sfn/command.rb +9 -11
  15. data/lib/sfn/command/conf.rb +7 -10
  16. data/lib/sfn/command/create.rb +8 -12
  17. data/lib/sfn/command/describe.rb +6 -8
  18. data/lib/sfn/command/destroy.rb +8 -10
  19. data/lib/sfn/command/diff.rb +18 -25
  20. data/lib/sfn/command/events.rb +15 -16
  21. data/lib/sfn/command/export.rb +13 -17
  22. data/lib/sfn/command/graph.rb +11 -13
  23. data/lib/sfn/command/graph/aws.rb +27 -29
  24. data/lib/sfn/command/graph/terraform.rb +22 -23
  25. data/lib/sfn/command/import.rb +13 -16
  26. data/lib/sfn/command/init.rb +5 -7
  27. data/lib/sfn/command/inspect.rb +26 -29
  28. data/lib/sfn/command/lint.rb +10 -12
  29. data/lib/sfn/command/list.rb +5 -8
  30. data/lib/sfn/command/print.rb +3 -5
  31. data/lib/sfn/command/promote.rb +0 -2
  32. data/lib/sfn/command/update.rb +42 -46
  33. data/lib/sfn/command/validate.rb +4 -6
  34. data/lib/sfn/command_module/base.rb +17 -25
  35. data/lib/sfn/command_module/callbacks.rb +12 -8
  36. data/lib/sfn/command_module/stack.rb +39 -43
  37. data/lib/sfn/command_module/template.rb +89 -90
  38. data/lib/sfn/config.rb +30 -31
  39. data/lib/sfn/config/conf.rb +1 -3
  40. data/lib/sfn/config/create.rb +5 -7
  41. data/lib/sfn/config/describe.rb +3 -5
  42. data/lib/sfn/config/diff.rb +1 -1
  43. data/lib/sfn/config/events.rb +6 -8
  44. data/lib/sfn/config/export.rb +4 -7
  45. data/lib/sfn/config/graph.rb +4 -6
  46. data/lib/sfn/config/import.rb +3 -5
  47. data/lib/sfn/config/init.rb +0 -1
  48. data/lib/sfn/config/inspect.rb +7 -9
  49. data/lib/sfn/config/lint.rb +4 -4
  50. data/lib/sfn/config/list.rb +3 -5
  51. data/lib/sfn/config/print.rb +3 -5
  52. data/lib/sfn/config/promote.rb +3 -5
  53. data/lib/sfn/config/update.rb +10 -12
  54. data/lib/sfn/config/validate.rb +18 -20
  55. data/lib/sfn/lint.rb +0 -2
  56. data/lib/sfn/lint/definition.rb +3 -5
  57. data/lib/sfn/lint/rule.rb +7 -8
  58. data/lib/sfn/lint/rule_set.rb +11 -20
  59. data/lib/sfn/monkey_patch/stack.rb +32 -34
  60. data/lib/sfn/monkey_patch/stack/azure.rb +0 -1
  61. data/lib/sfn/monkey_patch/stack/google.rb +15 -16
  62. data/lib/sfn/planner.rb +1 -3
  63. data/lib/sfn/planner/aws.rb +82 -89
  64. data/lib/sfn/provider.rb +21 -23
  65. data/lib/sfn/utils.rb +0 -2
  66. data/lib/sfn/utils/debug.rb +1 -2
  67. data/lib/sfn/utils/json.rb +3 -2
  68. data/lib/sfn/utils/object_storage.rb +1 -2
  69. data/lib/sfn/utils/output.rb +8 -9
  70. data/lib/sfn/utils/path_selector.rb +9 -10
  71. data/lib/sfn/utils/ssher.rb +2 -3
  72. data/lib/sfn/utils/stack_exporter.rb +20 -21
  73. data/lib/sfn/utils/stack_parameter_scrubber.rb +6 -7
  74. data/lib/sfn/utils/stack_parameter_validator.rb +14 -16
  75. data/lib/sfn/version.rb +1 -1
  76. data/sfn.gemspec +1 -1
  77. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 403602f06deb39fe3f2751236c97dd6f06443431
4
- data.tar.gz: 69f16806fb62a281b40d8f6588b4d5bf5772419d
2
+ SHA256:
3
+ metadata.gz: 8f2149802418fbce7d68ca416ec068c7190ac03050250fb8a0b9ad4fd35e4424
4
+ data.tar.gz: fc2970e2d4ca0b5e6548adbbf54c3026d6961c11d15def65f508a6a91fc4990d
5
5
  SHA512:
6
- metadata.gz: b36166fbdb2424563aec23d2c068616264582b25192ab4e377ae7312aa210d1565d721270af1885bc14196e4f56a05afa47afa1b926a815de278aa8c90591415
7
- data.tar.gz: 710cf024266fbe9725150f0930756e28d5a284b85db61ad033b048e106fd90bc3cd94c3c8e4b316f474b65e2148acc3e02afa9b06c2b3f676f557cb48a09c07d
6
+ metadata.gz: fb43de6444a47fa5e5b2a9ffd9d5e40c4ba2074b9c3bcfc2530e43956a9482f9ef9ae87ea66e4f992b7f131c18a32c90c9bb389a1d2d3eecf5eba4c82e5149d5
7
+ data.tar.gz: 67e9c1731ffddd88ab2e8706abcf590c18091b83a3bfae63cbbbee4c78b3d507df57db762927d0a36ca5e1041ae3397179d1a7f404b9b8154022f395ab70c6ac
@@ -1,3 +1,8 @@
1
+ # v3.0.30
2
+ * [fix] Comma delimited parameter type parsing (#270)
3
+ * [fix] Constant deprecations
4
+ * [enhancement] Add support for failed callbacks (#271)
5
+
1
6
  # v3.0.28
2
7
  * [fix] Fix stack save policy callback (#264)
3
8
  * [fix] Prevent processing unset event arrays
@@ -20,6 +20,7 @@ are generally invoked in two places:
20
20
 
21
21
  * `before` - Prior to the command's remote API request
22
22
  * `after` - Following the command's remote API request
23
+ * `failed` - Following failure of remote API request
23
24
 
24
25
  There are also callbacks available prior to the execution
25
26
  of a command. These can also be isolated to specific commands:
@@ -6,36 +6,31 @@ rescue Gem::LoadError => e
6
6
  # ignore
7
7
  end
8
8
 
9
- unless(defined?(Chef::Knife::CloudformationCreate))
10
-
9
+ unless defined?(Chef::Knife::CloudformationCreate)
11
10
  require 'sfn'
12
11
  require 'bogo'
13
12
 
14
13
  Chef::Config[:knife][:cloudformation] = {
15
14
  :options => {},
16
15
  :create => {},
17
- :update => {}
16
+ :update => {},
18
17
  }
19
18
  Chef::Config[:knife][:sparkleformation] = Chef::Config[:knife][:cloudformation]
20
19
 
21
20
  VALID_PREFIX = ['cloudformation', 'sparkleformation']
22
21
 
23
-
24
22
  Sfn::Config.constants.map do |konst|
25
23
  const = Sfn::Config.const_get(konst)
26
- if(const.is_a?(Class) && const.ancestors.include?(Bogo::Config))
24
+ if const.is_a?(Class) && const.ancestors.include?(Bogo::Config)
27
25
  const
28
26
  end
29
27
  end.compact.sort_by(&:to_s).each do |klass|
30
-
31
28
  VALID_PREFIX.each do |prefix|
32
-
33
29
  klass_name = klass.name.split('::').last
34
30
  command_class = "#{prefix.capitalize}#{klass_name}"
35
31
 
36
32
  knife_klass = Class.new(Chef::Knife)
37
33
  knife_klass.class_eval do
38
-
39
34
  include Bogo::AnimalStrings
40
35
 
41
36
  # Stub in names so knife will detect
@@ -54,7 +49,7 @@ unless(defined?(Chef::Knife::CloudformationCreate))
54
49
  # Properly load in configurations and execute command
55
50
  def run
56
51
  knife = Chef::Config[:knife]
57
- if(knife.respond_to?(:hash_dup))
52
+ if knife.respond_to?(:hash_dup)
58
53
  knife = knife.hash_dup
59
54
  end
60
55
  base = knife.to_smash
@@ -64,15 +59,15 @@ unless(defined?(Chef::Knife::CloudformationCreate))
64
59
  end.compact.first || {}
65
60
  cmd_config = cmd_config.to_smash
66
61
 
67
- reconfig = config.find_all do |k,v|
62
+ reconfig = config.find_all do |k, v|
68
63
  !v.nil?
69
64
  end
70
65
  # Split up options provided multiple arguments
71
- reconfig.map! do |k,v|
72
- if(v.is_a?(String) && v.include?(','))
66
+ reconfig.map! do |k, v|
67
+ if v.is_a?(String) && v.include?(',')
73
68
  v = v.split(',').map(&:strip)
74
69
  end
75
- [k,v]
70
+ [k, v]
76
71
  end
77
72
  n_config = Smash[reconfig]
78
73
  cmd_config = cmd_config.deep_merge(n_config)
@@ -83,7 +78,6 @@ unless(defined?(Chef::Knife::CloudformationCreate))
83
78
  def merge_configs
84
79
  config
85
80
  end
86
-
87
81
  end
88
82
  knife_klass.instance_variable_set(:@name, "Chef::Knife::#{command_class}")
89
83
  knife_klass.instance_variable_set(
@@ -93,12 +87,12 @@ unless(defined?(Chef::Knife::CloudformationCreate))
93
87
  knife_klass.banner "knife #{prefix} #{Bogo::Utility.snake(klass_name)}"
94
88
 
95
89
  Sfn::Config.options_for(klass).each do |name, info|
96
- if(info[:boolean])
90
+ if info[:boolean]
97
91
  short = "-#{info[:short]}"
98
92
  long = "--[no-]#{info[:long]}"
99
93
  else
100
94
  val = 'VALUE'
101
- if(info[:multiple])
95
+ if info[:multiple]
102
96
  val << '[,VALUE]'
103
97
  end
104
98
  short = "-#{info[:short]} #{val}"
@@ -110,7 +104,7 @@ unless(defined?(Chef::Knife::CloudformationCreate))
110
104
  :long => long,
111
105
  :boolean => info[:boolean],
112
106
  :default => info[:default],
113
- :description => info[:description]
107
+ :description => info[:description],
114
108
  }
115
109
  )
116
110
  end
data/lib/sfn.rb CHANGED
@@ -4,7 +4,6 @@ require 'bogo'
4
4
  require 'sparkle_formation'
5
5
 
6
6
  module Sfn
7
-
8
7
  autoload :ApiProvider, 'sfn/api_provider'
9
8
  autoload :Callback, 'sfn/callback'
10
9
  autoload :Provider, 'sfn/provider'
@@ -18,5 +17,4 @@ module Sfn
18
17
  autoload :CommandModule, 'sfn/command_module'
19
18
  autoload :Planner, 'sfn/planner'
20
19
  autoload :Lint, 'sfn/lint'
21
-
22
20
  end
@@ -2,9 +2,7 @@ require 'sfn'
2
2
 
3
3
  module Sfn
4
4
  module ApiProvider
5
-
6
5
  autoload :Google, 'sfn/api_provider/google'
7
6
  autoload :Terraform, 'sfn/api_provider/terraform'
8
-
9
7
  end
10
8
  end
@@ -2,7 +2,6 @@ require 'sfn'
2
2
 
3
3
  module Sfn
4
4
  module ApiProvider
5
-
6
5
  module Google
7
6
 
8
7
  # Disable remote template storage
@@ -21,11 +20,11 @@ module Sfn
21
20
  # @param c_stack [Miasma::Models::Orchestration::Stack]
22
21
  # @return [Hash]
23
22
  def extract_current_nested_template_parameters(stack, stack_name, c_stack)
24
- if(c_stack && c_stack.data[:parent_stack])
23
+ if c_stack && c_stack.data[:parent_stack]
25
24
  c_stack.data[:parent_stack].sparkleish_template(:remove_wrapper).fetch(
26
25
  :resources, stack_name, :properties, :parameters, Smash.new
27
26
  )
28
- elsif(stack.parent)
27
+ elsif stack.parent
29
28
  val = stack.parent.compile.resources.set!(stack_name).properties
30
29
  val.nil? ? Smash.new : val._dump
31
30
  else
@@ -43,16 +42,16 @@ module Sfn
43
42
  # @param val [Object]
44
43
  # @return [TrueClass, FalseClass]
45
44
  def function_set_parameter?(val)
46
- if(val)
45
+ if val
47
46
  val.start_with?('$(') || val.start_with?('{{')
48
47
  end
49
48
  end
50
49
 
51
50
  # Set parameters into parent resource properites
52
- def populate_parameters!(template, opts={})
51
+ def populate_parameters!(template, opts = {})
53
52
  result = super
54
53
  result.each_pair do |key, value|
55
- if(template.parent)
54
+ if template.parent
56
55
  template.parent.compile.resources.set!(template.name).properties.set!(key, value)
57
56
  else
58
57
  template.compile.resources.set!(template.name).properties.set!(key, value)
@@ -71,14 +70,12 @@ module Sfn
71
70
  # @param thing [SparkleFormation, Hash]
72
71
  # @return [Hash]
73
72
  def template_content(thing, *_)
74
- if(thing.is_a?(SparkleFormation))
73
+ if thing.is_a?(SparkleFormation)
75
74
  config[:sparkle_dump] ? thing.sparkle_dump : thing.dump
76
75
  else
77
76
  thing
78
77
  end
79
78
  end
80
-
81
79
  end
82
-
83
80
  end
84
81
  end
@@ -2,7 +2,6 @@ require 'sfn'
2
2
 
3
3
  module Sfn
4
4
  module ApiProvider
5
-
6
5
  module Terraform
7
6
 
8
7
  # Disable remote template storage
@@ -21,11 +20,11 @@ module Sfn
21
20
  # @param c_stack [Miasma::Models::Orchestration::Stack]
22
21
  # @return [Hash]
23
22
  def extract_current_nested_template_parameters(stack, stack_name, c_stack)
24
- if(c_stack && c_stack.data[:parent_stack])
23
+ if c_stack && c_stack.data[:parent_stack]
25
24
  c_stack.data[:parent_stack].sparkleish_template(:remove_wrapper).fetch(
26
25
  :resources, stack_name, :properties, :parameters, Smash.new
27
26
  )
28
- elsif(stack.parent)
27
+ elsif stack.parent
29
28
  val = stack.parent.compile.resources.set!(stack_name).properties
30
29
  val.nil? ? Smash.new : val._dump
31
30
  else
@@ -43,7 +42,7 @@ module Sfn
43
42
  # @param val [Object]
44
43
  # @return [TrueClass, FalseClass]
45
44
  def function_set_parameter?(val)
46
- if(val)
45
+ if val
47
46
  val.start_with?('${')
48
47
  end
49
48
  end
@@ -58,13 +57,12 @@ module Sfn
58
57
  # @param thing [SparkleFormation, Hash]
59
58
  # @return [Hash]
60
59
  def template_content(thing, *_)
61
- if(thing.is_a?(SparkleFormation))
60
+ if thing.is_a?(SparkleFormation)
62
61
  config[:sparkle_dump] ? thing.sparkle_dump : thing.dump
63
62
  else
64
63
  thing
65
64
  end
66
65
  end
67
-
68
66
  end
69
67
  end
70
68
  end
@@ -5,14 +5,13 @@ require 'sfn'
5
5
  module Sfn
6
6
  # Data caching helper
7
7
  class Cache
8
-
9
8
  class << self
10
9
 
11
10
  # Configure the caching approach to use
12
11
  #
13
12
  # @param type [Symbol] :redis or :local
14
13
  # @param args [Hash] redis connection arguments if used
15
- def configure(type, args={})
14
+ def configure(type, args = {})
16
15
  type = type.to_sym
17
16
  case type
18
17
  when :redis
@@ -49,9 +48,9 @@ module Sfn
49
48
  # @param kind [String, Symbol] data type
50
49
  # @param seconds [Integer]
51
50
  # return [Integer] seconds
52
- def apply_limit(kind, seconds=nil)
51
+ def apply_limit(kind, seconds = nil)
53
52
  @apply_limit ||= {}
54
- if(seconds)
53
+ if seconds
55
54
  @apply_limit[kind.to_sym] = seconds.to_i
56
55
  end
57
56
  @apply_limit[kind.to_sym].to_i
@@ -64,12 +63,11 @@ module Sfn
64
63
 
65
64
  # Ping the redis connection and reconnect if dead
66
65
  def redis_ping!
67
- if((@_pid && @_pid != Process.pid) || !Redis::Objects.redis.connected?)
66
+ if (@_pid && @_pid != Process.pid) || !Redis::Objects.redis.connected?
68
67
  Redis::Objects.redis.client.reconnect
69
68
  @_pid = Process.pid
70
69
  end
71
70
  end
72
-
73
71
  end
74
72
 
75
73
  # @return [String] custom key for this cache
@@ -79,7 +77,7 @@ module Sfn
79
77
  #
80
78
  # @param key [String, Array]
81
79
  def initialize(key)
82
- if(key.respond_to?(:sort))
80
+ if key.respond_to?(:sort)
83
81
  key = key.flatten if key.respond_to?(:flatten)
84
82
  key = key.map(&:to_s).sort
85
83
  end
@@ -92,7 +90,7 @@ module Sfn
92
90
  # @param name [Symbol] name of data
93
91
  # @param kind [Symbol] data type
94
92
  # @param args [Hash] options for data type
95
- def init(name, kind, args={})
93
+ def init(name, kind, args = {})
96
94
  get_storage(self.class.type, kind, name, args)
97
95
  true
98
96
  end
@@ -112,9 +110,9 @@ module Sfn
112
110
  args = registry.keys if args.empty?
113
111
  args.each do |key|
114
112
  value = self[key]
115
- if(value.respond_to?(:clear))
113
+ if value.respond_to?(:clear)
116
114
  value.clear
117
- elsif(value.respond_to?(:value))
115
+ elsif value.respond_to?(:value)
118
116
  value.value = nil
119
117
  end
120
118
  registry.delete(key)
@@ -131,7 +129,7 @@ module Sfn
131
129
  # @param name [Symbol] name of data
132
130
  # @param args [Hash] options for underlying storage
133
131
  # @return [Object]
134
- def get_storage(store_type, data_type, name, args={})
132
+ def get_storage(store_type, data_type, name, args = {})
135
133
  full_name = "#{key}_#{name}"
136
134
  result = nil
137
135
  case store_type.to_sym
@@ -139,14 +137,14 @@ module Sfn
139
137
  result = get_redis_storage(data_type, full_name.to_s, args)
140
138
  when :local
141
139
  @_local_cache ||= {}
142
- unless(@_local_cache[full_name.to_s])
140
+ unless @_local_cache[full_name.to_s]
143
141
  @_local_cache[full_name.to_s] = get_local_storage(data_type, full_name.to_s, args)
144
142
  end
145
143
  result = @_local_cache[full_name.to_s]
146
144
  else
147
145
  raise TypeError.new("Unsupported caching storage type encountered: #{store_type}")
148
146
  end
149
- unless(full_name == "#{key}_registry_#{key}")
147
+ unless full_name == "#{key}_registry_#{key}"
150
148
  registry[name.to_s] = data_type
151
149
  end
152
150
  result
@@ -158,7 +156,7 @@ module Sfn
158
156
  # @param full_name [Symbol]
159
157
  # @param args [Hash]
160
158
  # @return [Object]
161
- def get_redis_storage(data_type, full_name, args={})
159
+ def get_redis_storage(data_type, full_name, args = {})
162
160
  self.class.redis_ping!
163
161
  case data_type.to_sym
164
162
  when :array
@@ -183,22 +181,22 @@ module Sfn
183
181
  # @param args [Hash]
184
182
  # @return [Object]
185
183
  # @todo make proper singleton for local storage
186
- def get_local_storage(data_type, full_name, args={})
184
+ def get_local_storage(data_type, full_name, args = {})
187
185
  @storage ||= {}
188
186
  @storage[full_name] ||= case data_type.to_sym
189
- when :array
190
- []
191
- when :hash
192
- {}
193
- when :value
194
- LocalValue.new
195
- when :lock
196
- LocalLock.new(full_name, {:expiration => 60, :timeout => 0.1}.merge(args))
197
- when :stamped
198
- Stamped.new(full_name.sub("#{key}_", '').to_sym, get_local_storage(:value, full_name), self)
199
- else
200
- raise TypeError.new("Unsupported caching data type encountered: #{data_type}")
201
- end
187
+ when :array
188
+ []
189
+ when :hash
190
+ {}
191
+ when :value
192
+ LocalValue.new
193
+ when :lock
194
+ LocalLock.new(full_name, {:expiration => 60, :timeout => 0.1}.merge(args))
195
+ when :stamped
196
+ Stamped.new(full_name.sub("#{key}_", '').to_sym, get_local_storage(:value, full_name), self)
197
+ else
198
+ raise TypeError.new("Unsupported caching data type encountered: #{data_type}")
199
+ end
202
200
  end
203
201
 
204
202
  # Execute block within internal lock
@@ -216,7 +214,7 @@ module Sfn
216
214
  # @param name [String, Symbol]
217
215
  # @return [Object, NilClass]
218
216
  def [](name)
219
- if(kind = registry[name.to_s])
217
+ if kind = registry[name.to_s]
220
218
  get_storage(self.class.type, kind, name)
221
219
  else
222
220
  nil
@@ -246,9 +244,9 @@ module Sfn
246
244
  # @param kind [String, Symbol] data type
247
245
  # @param seconds [Integer]
248
246
  # return [Integer]
249
- def apply_limit(kind, seconds=nil)
247
+ def apply_limit(kind, seconds = nil)
250
248
  @apply_limit ||= {}
251
- if(seconds)
249
+ if seconds
252
250
  @apply_limit[kind.to_sym] = seconds.to_i
253
251
  end
254
252
  @apply_limit[kind.to_sym].to_i
@@ -259,13 +257,13 @@ module Sfn
259
257
  # @param lock_name [String, Symbol] name of lock
260
258
  # @param raise_on_locked [TrueClass, FalseClass] raise execption if lock wait times out
261
259
  # @return [Object] result of yield
262
- def locked_action(lock_name, raise_on_locked=false)
260
+ def locked_action(lock_name, raise_on_locked = false)
263
261
  begin
264
262
  self[lock_name].lock do
265
263
  yield
266
264
  end
267
265
  rescue => e
268
- if(e.class.to_s.end_with?('Timeout'))
266
+ if e.class.to_s.end_with?('Timeout')
269
267
  raise if raise_on_locked
270
268
  else
271
269
  raise
@@ -277,6 +275,7 @@ module Sfn
277
275
  class LocalValue
278
276
  # @return [Object] value
279
277
  attr_accessor :value
278
+
280
279
  def initialize(*args)
281
280
  @value = nil
282
281
  end
@@ -284,7 +283,6 @@ module Sfn
284
283
 
285
284
  # Simple lock for memory cache
286
285
  class LocalLock
287
-
288
286
  class LocalLockTimeout < RuntimeError
289
287
  end
290
288
 
@@ -300,7 +298,7 @@ module Sfn
300
298
  # @param name [Symbol] name of lock
301
299
  # @param args [Hash]
302
300
  # @option args [Numeric] :timeout
303
- def initialize(name, args={})
301
+ def initialize(name, args = {})
304
302
  @_key = name
305
303
  @_timeout = args.fetch(:timeout, -1).to_f
306
304
  @_lock = Mutex.new
@@ -313,17 +311,17 @@ module Sfn
313
311
  def lock
314
312
  locked = false
315
313
  attempt_start = Time.now.to_f
316
- while(!locked && (_timeout < 0 || Time.now.to_f - attempt_start < _timeout))
314
+ while (!locked && (_timeout < 0 || Time.now.to_f - attempt_start < _timeout))
317
315
  locked = _lock.try_lock
318
316
  end
319
- if(locked)
317
+ if locked
320
318
  begin
321
319
  yield
322
320
  ensure
323
321
  _lock.unlock if _lock.locked?
324
322
  end
325
323
  else
326
- if(defined?(Redis))
324
+ if defined?(Redis)
327
325
  raise Redis::Lock::LockTimeout.new "Timeout on lock #{_key} exceeded #{_timeout} sec"
328
326
  else
329
327
  raise LocalLockTimeout.new "Timeout on lock #{_key} exceeded #{_timeout} sec"
@@ -387,6 +385,5 @@ module Sfn
387
385
  !set? || @cache.time_check_allow?(@name, @base.value[:stamp])
388
386
  end
389
387
  end
390
-
391
388
  end
392
389
  end