maybe_client 1.0.0

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 (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/maybe_client.rb +45 -0
  3. metadata +89 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9e6ed6d296d1b6ee931b1c9fe853c5b92d58fb47
4
+ data.tar.gz: 2428a1af171c4c4a0b2d8910d17a0c74deac0192
5
+ SHA512:
6
+ metadata.gz: 652f55cf0f17097c0db0a2ad34f39525d193f9c319ea6cc55e1cff1514df970e4a2e2b232cbab360dbfa9c6f571c6d8ce514dcc8946d4200725b381499f520b5
7
+ data.tar.gz: 4ef0116b68c35003e4a58e18dd9e4e50d24c64eafabbda57fa5512f8c10a48612fee3465de79081ea7ef219593f7fc4e8237bc9ec4cea653a805bb1382e63fdc
@@ -0,0 +1,45 @@
1
+ class MaybeClient
2
+ DELAY = 60
3
+
4
+ def initialize(client_class, *connect_params)
5
+ @connect_params = connect_params
6
+ @client_class = client_class
7
+
8
+ initialize_client
9
+ end
10
+
11
+ # Used to delegate everything to @client
12
+ def method_missing(method, *args)
13
+ return if noop?
14
+ initialize_client unless @client
15
+ return if noop?
16
+
17
+ result = nil
18
+
19
+ begin
20
+ @fail_at = nil
21
+ result = @client.send(method, *args)
22
+ rescue Exception => e
23
+ handle_exception
24
+ end
25
+
26
+ result
27
+ end
28
+
29
+ private
30
+ def noop?
31
+ @fail_at && @fail_at + DELAY > Time.now
32
+ end
33
+
34
+ def handle_exception
35
+ @fail_at = Time.now
36
+ end
37
+
38
+ def initialize_client
39
+ begin
40
+ @client = @client_class.new(*@connect_params)
41
+ rescue Exception => e
42
+ handle_exception
43
+ end
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maybe_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jan Renra Gloser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.4.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.4.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: timecop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.0
55
+ description:
56
+ email:
57
+ - jan.renra.gloser@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/maybe_client.rb
63
+ homepage: https://github.com/renra/ruby-maybe_client
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.4.5.1
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Wrapper for connection clients that handles outages without raising errors
87
+ (and thus taking the application down). Ideal for making the application resilient
88
+ in case of 3rd party failures (think your redis cache instance goes down)
89
+ test_files: []