mqtt-ccutrer 1.0.2 → 1.0.3

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: 5b93bce8e1cc0e50a0161ac2447fbff2c293ad89f64dc98cb848e20026e754e3
4
- data.tar.gz: 4b480e5ffb4df550469d112274f6c831b96f4a2118bb29e32940156b9dccce58
3
+ metadata.gz: c95449b66faaba1f857dbb64e535b2f4a8565a91a8611aa3b53d1b1a3c802f7d
4
+ data.tar.gz: 053ce243061cf20b3326d53e7fda9afaa82972d4029631e6e0857efc465e7bcf
5
5
  SHA512:
6
- metadata.gz: 3227b778e824d891845cab272ffe73f875ffe2de3440a56e1a3f73bffb5d6fa9edb41844665aead5411276c0241ef4f176fc369b98d1398c54bbdf78dc9103d9
7
- data.tar.gz: 51254e256507a8c01dd9197266eed692ccad64c3a7b0baa8bbc3ec50350ea712bc2a8bbfd1b575fca4527d5fe4da0a706f33aa998a932aca8a517f5af40b6721
6
+ metadata.gz: e465141738a3352c562474041f199a260496d9d499d81899613381de8521a9fb215bdde351b608ac9630a463b3fa2e2dd4cfe22046ab179926d0c657ffebaa08
7
+ data.tar.gz: 0b87b975e3c9a792f17dcc663c9aa0c0be764a6866eeeedb1a88ba9d38511f661995c412920d6798e580929317d4e633fdd744f33177fb7609c30542b4394e5d
data/lib/mqtt/client.rb CHANGED
@@ -43,14 +43,17 @@ module MQTT
43
43
  attr_accessor :resend_limit
44
44
 
45
45
  # How many attempts to re-establish a connection after it drops before
46
- # giving up (default 5)
46
+ # giving up (default 5); nil for unlimited retries
47
47
  attr_accessor :reconnect_limit
48
48
 
49
49
  # How long to wait between re-connection attempts (exponential - i.e.
50
50
  # immediately after first drop, then 5s, then 25s, then 125s, etc.
51
- # when theis value defaults to 5)
51
+ # when this value defaults to 5)
52
52
  attr_accessor :reconnect_backoff
53
53
 
54
+ # the longest amount of time to wait before attempting a reconnect
55
+ attr_accessor :reconnect_backoff_max
56
+
54
57
  # Username to authenticate to the server with
55
58
  attr_accessor :username
56
59
 
@@ -80,7 +83,8 @@ module MQTT
80
83
  ack_timeout: 5,
81
84
  resend_limit: 5,
82
85
  reconnect_limit: 5,
83
- reconnect_backoff: 5,
86
+ reconnect_backoff: 2,
87
+ reconnect_backoff_max: 30,
84
88
  username: nil,
85
89
  password: nil,
86
90
  will_topic: nil,
@@ -130,8 +134,11 @@ module MQTT
130
134
  # client = MQTT::Client.new('myserver.example.com', 18830)
131
135
  # client = MQTT::Client.new(host: 'myserver.example.com')
132
136
  # client = MQTT::Client.new(host: 'myserver.example.com', keep_alive: 30)
137
+ # client = MQTT::Client.new(uri: 'mqtt://myserver.example.com', keep_alive: 30)
133
138
  #
134
139
  def initialize(host = nil, port = nil, **attributes)
140
+ host = attributes.delete(:uri) if attributes.key?(:uri)
141
+
135
142
  # Set server URI from environment if present
136
143
  if host.nil? && port.nil? && attributes.empty? && ENV['MQTT_SERVER']
137
144
  attributes.merge!(parse_uri(ENV['MQTT_SERVER']))
@@ -560,9 +567,10 @@ module MQTT
560
567
  rescue
561
568
  @socket&.close
562
569
  @socket = nil
570
+ retries += 1
563
571
 
564
- if (retries += 1) < @reconnect_limit
565
- sleep @reconnect_backoff ** retries
572
+ if @reconnect_limit.nil? || retries < @reconnect_limit
573
+ sleep [@reconnect_backoff ** retries, @reconnect_backoff_max].min
566
574
  retry
567
575
  end
568
576
  end
data/lib/mqtt/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module MQTT
4
4
  # The version number of the MQTT gem
5
- VERSION = '1.0.2'
5
+ VERSION = '1.0.3'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mqtt-ccutrer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-06 00:00:00.000000000 Z
11
+ date: 2022-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  - !ruby/object:Gem::Version
175
175
  version: '0'
176
176
  requirements: []
177
- rubygems_version: 3.1.2
177
+ rubygems_version: 3.3.5
178
178
  signing_key:
179
179
  specification_version: 4
180
180
  summary: Implementation of the MQTT protocol