lusnoc 1.0.1.81647 → 1.0.1.134629

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
  SHA256:
3
- metadata.gz: 50b154f750c90199db9d2fdf86287bbc5baf66a81487ae159ad967acf46648ed
4
- data.tar.gz: f26b45a43f07cb5b74b65a2668e57604d400d76725b4e9ad6dbf65ed3bb3203c
3
+ metadata.gz: d41d26d751d0c33f77cfd692c36d78327f16ac6ca23cf07f4688192038e74f42
4
+ data.tar.gz: 669c67d00e35b4853e855940bf1f940e753c5dd53c2df863e2c235227bb7f1e9
5
5
  SHA512:
6
- metadata.gz: 277c9b797899a742a635f4ab8fc58bbf0d92992d5f9e9019f32dd29469cf30abcc933880da135e5ce1f7d44a6607e33813d07642db27ff14d59506562a469d3b
7
- data.tar.gz: 0fb138ae084b8639ff087427bea5e97540a94bcd1ee870a92d3e35b37bdbd3e54583849dd60705bfc5d4b06141c16c22cc78dd3efebb30075cf9775b65414db1
6
+ metadata.gz: 6c8eb0b142f5dd30c3873c6e3785fdb5ed59ce4c85d0ffd99e2c22e08d328839a83c883bfdc82df9ce1eeba9305ab144835a217d48d032ad34c82ed12f17a350
7
+ data.tar.gz: af4afbf1c9104bef1366e150527239ee0e029df5ea0f60cac2df39ccc6318702b443b31c3800d075a0f41552b924e82bc09d75712021a0eba3a1a4376af0b1e1
data/README.md CHANGED
@@ -30,7 +30,7 @@ Lusnoc allows you to interact with Consul to provide distributed locks(mutex) to
30
30
  * Lusnoc enforces you to manualy renew session(through callback or explicit check) but provide background session checker
31
31
  * Lusnoc tries to carefuly handle timeouts and expiration using Consul [blocking queries](https://www.consul.io/api/features/blocking.html)
32
32
 
33
- # Usage
33
+ ## Usage
34
34
 
35
35
  Simply instantiate a new `Lusnoc::Mutex`, giving it the key you want to use
36
36
  as the "lock":
@@ -106,7 +106,7 @@ Typical usage scenario:
106
106
  end
107
107
  ```
108
108
 
109
- # Installation
109
+ ## Installation
110
110
 
111
111
  It's a gem:
112
112
  ```bash
@@ -117,4 +117,9 @@ There's also the wonders of [the Gemfile](http://bundler.io):
117
117
  gem 'lusnoc'
118
118
  ```
119
119
 
120
+ ## Mirrors
121
+
122
+ * GitFlic: [https://gitflic.ru/project/rndsoft/lusnoc](https://gitflic.ru/project/rndsoft/lusnoc)
123
+ * Github: [https://github.com/RND-SOFT/lusnoc](https://github.com/RND-SOFT/lusnoc)
124
+
120
125
 
@@ -4,7 +4,7 @@ module Lusnoc
4
4
  # Methods for configuring Lusnoc
5
5
  class Configuration
6
6
 
7
- attr_accessor :url, :acl_token, :logger
7
+ attr_accessor :url, :acl_token, :logger, :http_timeout
8
8
 
9
9
  # Override defaults for configuration
10
10
  # @param url [String] consul's connection URL
@@ -13,6 +13,7 @@ module Lusnoc
13
13
  @url = url
14
14
  @acl_token = acl_token
15
15
  @logger = Logger.new(STDOUT, level: Logger::INFO, progname: 'Lusnoc')
16
+ @http_timeout = 5
16
17
  end
17
18
 
18
19
  end
data/lib/lusnoc.rb CHANGED
@@ -24,7 +24,7 @@ module Lusnoc
24
24
  yield(configuration)
25
25
  end
26
26
 
27
- def http_get(url, timeout: 5)
27
+ def http_get(url, timeout: Lusnoc.configuration.http_timeout)
28
28
  uri = URI(url)
29
29
 
30
30
  with_http(uri, timeout: timeout) do |http|
@@ -36,7 +36,7 @@ module Lusnoc
36
36
  end
37
37
  end
38
38
 
39
- def http_put(url, value = nil, timeout: 5)
39
+ def http_put(url, value = nil, timeout: Lusnoc.configuration.http_timeout)
40
40
  uri = URI(url)
41
41
  data = value.is_a?(String) ? value : JSON.generate(value) unless value.nil?
42
42
 
@@ -55,14 +55,33 @@ module Lusnoc
55
55
  private
56
56
 
57
57
  def with_http(uri, timeout:)
58
- Net::HTTP.start(uri.host, uri.port,
59
- use_ssl: uri.scheme == 'https',
60
- read_timeout: timeout,
61
- open_timeout: 1,
62
- continue_timeout: 1,
63
- write_timeout: 1,
64
- max_retries: 0) do |http|
65
- yield(http)
58
+ with_retry(delay: 0.1) do
59
+ Net::HTTP.start(uri.host, uri.port,
60
+ use_ssl: uri.scheme == 'https',
61
+ read_timeout: timeout,
62
+ open_timeout: timeout,
63
+ continue_timeout: timeout,
64
+ write_timeout: timeout,
65
+ max_retries: 1) do |http|
66
+ yield(http)
67
+ end
68
+ end
69
+ end
70
+
71
+ def with_retry(count = 2, delay: 1, klass: nil)
72
+ begin
73
+ retries ||= 0
74
+ yield(retries)
75
+ rescue StandardError => e
76
+ sleep(delay + (retries**2) * delay)
77
+ if (retries += 1) < count
78
+ retry
79
+ else
80
+ raise if klass.nil?
81
+ return nil if klass == :skip
82
+
83
+ raise klass.new(e.message)
84
+ end
66
85
  end
67
86
  end
68
87
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lusnoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1.81647
4
+ version: 1.0.1.134629
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samoilenko Yuri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-08 00:00:00.000000000 Z
11
+ date: 2023-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler