twingly-amqp 4.3.0 → 4.4.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.
- checksums.yaml +5 -5
- data/README.md +7 -3
- data/lib/twingly/amqp/ping_options.rb +25 -9
- data/lib/twingly/amqp/pinger.rb +5 -6
- data/lib/twingly/amqp/session.rb +0 -4
- data/lib/twingly/amqp/subscription.rb +2 -14
- data/lib/twingly/amqp/version.rb +1 -1
- metadata +19 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: afa12f0f296e62925302731fdcf55c620ef593536340455b757e18168e6d76b7
|
4
|
+
data.tar.gz: 0545a905095cb041cd1f91556b4ba868444c2c25d27117079f73a4ee8c6d0ad4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7c2e089cf8cd98f78706bb5e7dcbde5da880374d3d1947165152312b7757d34eef36de279031af3cd6e7662a0bef06a4ad8ca98936a99f33fafecd0e8bc2e2c
|
7
|
+
data.tar.gz: 12e0033eccf69edbb3e657cf67bb0486e4bab449b7acebf24c0a88b87477321d1ced6e2d5df0b10719e484841c429a17dd749f98ee2edc10565293af6f091e79
|
data/README.md
CHANGED
@@ -145,9 +145,11 @@ pinger = Twingly::AMQP::Pinger.new(
|
|
145
145
|
|
146
146
|
# Optional, options can also be given to #ping
|
147
147
|
pinger.default_ping_options do |options|
|
148
|
-
options.provider_name
|
149
|
-
options.source_ip
|
150
|
-
options.priority
|
148
|
+
options.provider_name = "TestProvider"
|
149
|
+
options.source_ip = "?.?.?.?"
|
150
|
+
options.priority = 1
|
151
|
+
# Optional keys/values that will be included in each ping message
|
152
|
+
options.custom_options = { my_option: "This is my own option" }
|
151
153
|
end
|
152
154
|
|
153
155
|
urls = [
|
@@ -155,10 +157,12 @@ urls = [
|
|
155
157
|
]
|
156
158
|
|
157
159
|
# Optional, is merged with the default options above
|
160
|
+
# options given to #ping takes precedence over the default options
|
158
161
|
options = {
|
159
162
|
provider_name: "a-provider-name",
|
160
163
|
source_ip: "?.?.?.?",
|
161
164
|
priority: 1,
|
165
|
+
custom_options: { my_other_option: "Another option" },
|
162
166
|
}
|
163
167
|
|
164
168
|
pinger.ping(urls, options) do |pinged_url|
|
@@ -3,25 +3,40 @@ module Twingly
|
|
3
3
|
class PingOptions
|
4
4
|
attr_accessor :provider_name, :source_ip, :priority
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
attr_reader :custom_options
|
7
|
+
|
8
|
+
def initialize(provider_name: nil, source_ip: nil, priority: nil,
|
9
|
+
custom_options: {})
|
10
|
+
self.provider_name = provider_name
|
11
|
+
self.source_ip = source_ip
|
12
|
+
self.priority = priority
|
13
|
+
self.custom_options = custom_options
|
10
14
|
|
11
15
|
yield self if block_given?
|
12
16
|
end
|
13
17
|
|
18
|
+
def custom_options=(options)
|
19
|
+
unless options.respond_to?(:to_h)
|
20
|
+
raise ArgumentError, "custom_options must respond to 'to_h'"
|
21
|
+
end
|
22
|
+
|
23
|
+
@custom_options = options.to_h
|
24
|
+
end
|
25
|
+
|
14
26
|
def to_h
|
15
27
|
{
|
16
|
-
automatic_ping: false,
|
17
28
|
provider_name: provider_name,
|
18
29
|
source_ip: source_ip,
|
19
30
|
priority: priority,
|
31
|
+
custom_options: custom_options,
|
20
32
|
}
|
21
33
|
end
|
22
34
|
|
23
35
|
def validate
|
24
|
-
missing_keys = to_h.select
|
36
|
+
missing_keys = to_h.select do |key, value|
|
37
|
+
key != :custom_options && value.to_s.empty?
|
38
|
+
end.keys
|
39
|
+
|
25
40
|
if missing_keys.any?
|
26
41
|
raise ArgumentError, "Required options not set: #{missing_keys}"
|
27
42
|
end
|
@@ -29,9 +44,10 @@ module Twingly
|
|
29
44
|
|
30
45
|
def merge(other)
|
31
46
|
PingOptions.new do |options|
|
32
|
-
options.provider_name
|
33
|
-
options.source_ip
|
34
|
-
options.priority
|
47
|
+
options.provider_name = other.provider_name || provider_name
|
48
|
+
options.source_ip = other.source_ip || source_ip
|
49
|
+
options.priority = other.priority || priority
|
50
|
+
options.custom_options = custom_options.merge(other.custom_options)
|
35
51
|
end
|
36
52
|
end
|
37
53
|
end
|
data/lib/twingly/amqp/pinger.rb
CHANGED
@@ -26,12 +26,11 @@ module Twingly
|
|
26
26
|
options.validate
|
27
27
|
|
28
28
|
Array(urls).each do |url|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
next if cached?(url)
|
30
|
+
publish(url, options)
|
31
|
+
cache!(url)
|
32
32
|
|
33
|
-
|
34
|
-
end
|
33
|
+
yield url if block_given?
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
@@ -67,7 +66,7 @@ module Twingly
|
|
67
66
|
end
|
68
67
|
|
69
68
|
class NullCache
|
70
|
-
def self.cached?(
|
69
|
+
def self.cached?(_url)
|
71
70
|
false
|
72
71
|
end
|
73
72
|
|
data/lib/twingly/amqp/session.rb
CHANGED
@@ -27,10 +27,6 @@ module Twingly
|
|
27
27
|
options[:pass] ||= password_from_env
|
28
28
|
options[:hosts] ||= hosts_from_env
|
29
29
|
|
30
|
-
# Used as a workaround for
|
31
|
-
# https://github.com/ruby-amqp/bunny/issues/446
|
32
|
-
options[:hosts] = options.fetch(:hosts).dup
|
33
|
-
|
34
30
|
default_connection_options.merge(options)
|
35
31
|
end
|
36
32
|
|
@@ -63,7 +63,7 @@ module Twingly
|
|
63
63
|
|
64
64
|
private
|
65
65
|
|
66
|
-
def create_consumer
|
66
|
+
def create_consumer
|
67
67
|
@queue.subscribe(subscribe_options) do |delivery_info, metadata, payload|
|
68
68
|
@before_handle_message_callback.call(payload)
|
69
69
|
|
@@ -74,7 +74,7 @@ module Twingly
|
|
74
74
|
channel: @channel,
|
75
75
|
)
|
76
76
|
|
77
|
-
|
77
|
+
yield message
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -112,18 +112,6 @@ module Twingly
|
|
112
112
|
tag_name = Socket.gethostname
|
113
113
|
@channel.generate_consumer_tag(tag_name)
|
114
114
|
end
|
115
|
-
|
116
|
-
def setup_traps
|
117
|
-
[:INT, :TERM].each do |signal|
|
118
|
-
Signal.trap(signal) do
|
119
|
-
# Exit fast if we've already got a signal since before
|
120
|
-
exit!(true) if cancel?
|
121
|
-
|
122
|
-
# Set cancel flag, cancels consumers
|
123
|
-
cancel!
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
115
|
end
|
128
116
|
end
|
129
117
|
end
|
data/lib/twingly/amqp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twingly-amqp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Twingly AB
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -16,56 +16,62 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.6'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.6.2
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
29
|
+
version: '2.6'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.6.2
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
34
|
+
name: rake
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
39
|
+
version: '10.0'
|
34
40
|
type: :development
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
46
|
+
version: '10.0'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
48
|
+
name: rspec
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
53
|
+
version: '3'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
60
|
+
version: '3'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: rubocop
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
65
|
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
67
|
+
version: '0.49'
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
72
|
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
74
|
+
version: '0.49'
|
69
75
|
description: Publish and subscribe to messages via RabbitMQ
|
70
76
|
email:
|
71
77
|
- support@twingly.com
|
@@ -104,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
110
|
version: '0'
|
105
111
|
requirements: []
|
106
112
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.7.6
|
108
114
|
signing_key:
|
109
115
|
specification_version: 4
|
110
116
|
summary: Ruby library for talking to RabbitMQ
|