vx-container_connector 0.2.3 → 0.2.4

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: 2e353cc8520cbb57bf2208caba4dd5d4fd623f86
4
- data.tar.gz: e7047733f64839506517f74f0ebeefb6cf393610
3
+ metadata.gz: e8d1d2a512151ac69a604b6756aa939d6aa6be35
4
+ data.tar.gz: e5e247f6562b4e15779f41098c1ed97d5ffbc72f
5
5
  SHA512:
6
- metadata.gz: 32235b2e4cc02425e6becc923ebffbf7fb621df3602d981bb48db33e039fe54cce55761ce5d52394ba7ec94301afe9d66bb1c5543714c6991c5b8759989b8815
7
- data.tar.gz: 79e0ffc0ba1c3ef204aaf947c121c105c285cfca9f0a81597911bd6b8bd8effbcb7f0ad3aa5315762c2f55fc6fdc50642bd4df4caf004884f20c4e06b3a16b0e
6
+ metadata.gz: a375c89e7b098c1011f7be78ddb00f04a27d1b7fdcd7b00332cb175136243c8c68c7fb2c51ceaef7b0a3c6db4f00eb7302f31a7135fc8668092997dae84315fe
7
+ data.tar.gz: 1a352e186e139f0a22827903ebffe2a2a565cfe4b1d0f846608f51f0cff45ceff4c857401672b21abb8863bca63b234112d5d8ce4f727cfaf688a63b66011cc8
@@ -94,8 +94,8 @@ module Vx
94
94
  sleep 3
95
95
  yield container
96
96
  ensure
97
- container.stop
98
- logger.info "stop container #{container.id}"
97
+ container.kill
98
+ logger.info "kill container #{container.id}"
99
99
  end
100
100
  end
101
101
 
@@ -0,0 +1,40 @@
1
+ module Vx
2
+ module ContainerConnector
3
+ module Retriable
4
+ # This will catch any exception and retry twice (three tries total):
5
+ # with_retries { ... }
6
+ #
7
+ # This will catch any exception and retry four times (five tries total):
8
+ # with_retries(:limit => 5) { ... }
9
+ #
10
+ # This will catch a specific exception and retry once (two tries total):
11
+ # with_retries(Some::Error, :limit => 2) { ... }
12
+ #
13
+ # You can also sleep inbetween tries. This is helpful if you're hoping
14
+ # that some external service recovers from its issues.
15
+ # with_retries(Service::Error, :sleep => 1) { ... }
16
+ #
17
+ def with_retries(*args, &block)
18
+ options = args.last.is_a?(Hash) ? args.pop : {}
19
+ exceptions = args
20
+
21
+ options[:limit] ||= 3
22
+ options[:sleep] ||= 0
23
+ exceptions = [Exception] if exceptions.empty?
24
+
25
+ retried = 0
26
+ begin
27
+ yield
28
+ rescue *exceptions => e
29
+ if retried + 1 < options[:limit]
30
+ retried += 1
31
+ sleep options[:sleep]
32
+ retry
33
+ else
34
+ raise e
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  module Vx
2
2
  module ContainerConnector
3
- VERSION = "0.2.3"
3
+ VERSION = "0.2.4"
4
4
  end
5
5
  end
@@ -4,8 +4,10 @@ require File.expand_path("../container_connector/errors", __FILE__)
4
4
  module Vx
5
5
  module ContainerConnector
6
6
 
7
- autoload :Local, File.expand_path("../container_connector/local", __FILE__)
8
- autoload :Docker, File.expand_path("../container_connector/docker", __FILE__)
7
+ autoload :Local, File.expand_path("../container_connector/local", __FILE__)
8
+ autoload :Docker, File.expand_path("../container_connector/docker", __FILE__)
9
+ autoload :Retriable, File.expand_path("../container_connector/mixin/retriable", __FILE__)
10
+
9
11
 
10
12
  extend self
11
13
 
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ class TestRetriable
4
+ include Vx::ContainerConnector::Retriable
5
+
6
+ class Error < Exception ; end
7
+ end
8
+
9
+ describe Vx::ContainerConnector::Retriable do
10
+ let(:proxy) { TestRetriable.new }
11
+
12
+ it "should rescue 2 times" do
13
+ expect(test_retriable(2)).to eq :pass
14
+ end
15
+
16
+ it "should fail on 3 attempt" do
17
+ expect {
18
+ test_retriable(3)
19
+ }.to raise_error(TestRetriable::Error, "0")
20
+ end
21
+
22
+ def test_retriable(n)
23
+ proxy.with_retries(TestRetriable::Error, limit: 3, sleep: 0.1) do
24
+ if n != 0
25
+ n -= 1
26
+ raise TestRetriable::Error.new(n.to_s)
27
+ end
28
+ :pass
29
+ end
30
+ end
31
+
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vx-container_connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-20 00:00:00.000000000 Z
11
+ date: 2014-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api
@@ -113,10 +113,12 @@ files:
113
113
  - lib/vx/container_connector/errors.rb
114
114
  - lib/vx/container_connector/local.rb
115
115
  - lib/vx/container_connector/local/spawner.rb
116
+ - lib/vx/container_connector/mixin/retriable.rb
116
117
  - lib/vx/container_connector/version.rb
117
118
  - spec/lib/container_connector_spec.rb
118
119
  - spec/lib/docker_spec.rb
119
120
  - spec/lib/local_spec.rb
121
+ - spec/lib/mixin/retriable_spec.rb
120
122
  - spec/spec_helper.rb
121
123
  - vx-container_connector.gemspec
122
124
  homepage: ''
@@ -147,4 +149,5 @@ test_files:
147
149
  - spec/lib/container_connector_spec.rb
148
150
  - spec/lib/docker_spec.rb
149
151
  - spec/lib/local_spec.rb
152
+ - spec/lib/mixin/retriable_spec.rb
150
153
  - spec/spec_helper.rb