lusnoc 1.0.0.70325 → 1.0.1.81655

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb34cf9c0298c287853840b632bba99c26366c00d22c6707edff4c100c79b6ea
4
- data.tar.gz: ff3cf1b6d5db904261f0e6ecceb3393ba9e5ea14b408bf8150a816fd2ac6ee55
3
+ metadata.gz: 9d8b6fb803c649e27c50cc60efa54a883457c5b5a326e06a2710d4b33c35624a
4
+ data.tar.gz: 88432501ac7df9c532d8ea95c9425aa7b3aa381ebddf9092a67fd207af6c91e6
5
5
  SHA512:
6
- metadata.gz: 2fe4689e9edf5be69f6d0c881c2ac3ad40248e649164347c4bcba6134530d38bbe4aa90fe187ffba4f7452f85a9f8c9e766194f69b32c0586ab00392c9b3b65f
7
- data.tar.gz: 7cde1cc5d3617a4de67958528b07cf2ab7a81faa04653174df8c654375c3c090b4de483a3fd024620e8bdbaf28320b79070260ce0d5a75e00b59619d0e5ba542
6
+ metadata.gz: c4deed444ac90080936f49962c954d4f81799523ea2d054e247a835b57b85204a7150a6e7040034fc85b6fa0feba69eedf01aeeb1b55e75a85b2a902a87857de
7
+ data.tar.gz: 1dd863908e52441edfc91c62e86ba8abcefad15d22f445889057a2ce3cf9386d8d42557d9839c1966f25dce2d48597f214bf20effb11dea027e69266ff8898fc
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2019 Рнд Софт
1
+ Copyright (c) 2014-2022 Рнд Софт
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
@@ -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
@@ -1,6 +1,6 @@
1
1
  module Lusnoc
2
2
 
3
- VERSION = '1.0.0'.freeze
3
+ VERSION = '1.0.1'.freeze
4
4
 
5
5
  end
6
6
 
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: 1)
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: 1)
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.0.70325
4
+ version: 1.0.1.81655
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samoilenko Yuri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-14 00:00:00.000000000 Z
11
+ date: 2022-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler