eventq 2.5.2 → 2.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/eventq/eventq_aws/sns.rb +28 -2
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31eddc31f997ed63f4d4fa78994f72650530d3329094ed53a95fc624726a8233
4
- data.tar.gz: 67b7a029e4527f5266a6d4cd6d91b6ad8394d415254920e375aae3e2ea2b0114
3
+ metadata.gz: 694ed72384dbe126f58a0813b002ba2ba597fd4cd0d2f477a3fd68d9f12396bc
4
+ data.tar.gz: 00eb675d57cd63827d55d59f9af6083d830226dcac7e2db3d281099cf30c8a06
5
5
  SHA512:
6
- metadata.gz: 8e4179b1738e910c44a000089d207e9234d1350892b5612760f757dcb486e6163c50adf249cc4c1a02f312aa30ce98cc1fbc5b2b37c32fb4d068d8be8ed4d380
7
- data.tar.gz: 752895dbf0f9fc1defeee0f93725227d7d8a6cb2a8052643cd5c76b8259dc7c44c7699244a04c155d769c5c0f891530e25ec0fe46847ae096c826f72ddcca8a8
6
+ metadata.gz: 7e5368f9ac76beb781594a4d058bf4f71dfcf8b406d94af08aa3aee5edf67ff607edcd3eec54dceaa4c5d1f4ecff995500076353c2b4d4be6afaf6c03fb7c92e
7
+ data.tar.gz: ea183d9565147acaa569cec2c7e8f8ceeb43dc6a152085f28ea31d7e737ee7b2b335340388ace7d84221909934bb66da08cf4cab5286511a3c2ac18e9bcac0c9
@@ -32,6 +32,7 @@ module EventQ
32
32
  end
33
33
 
34
34
  # Check if a TopicArn exists. This will check with AWS if necessary and cache the results if one is found
35
+ #
35
36
  # @return TopicArn [String]
36
37
  def get_topic_arn(event_type, region = nil)
37
38
  _event_type = EventQ.create_event_type(event_type)
@@ -39,8 +40,7 @@ module EventQ
39
40
 
40
41
  arn = @@topic_arns[topic_key]
41
42
  unless arn
42
- response = sns.list_topics
43
- arn = response.topics.detect { |topic| topic.topic_arn.end_with?(":#{_event_type}") }&.topic_arn
43
+ arn = find_topic(_event_type)
44
44
 
45
45
  @@topic_arns[topic_key] = arn if arn
46
46
  end
@@ -62,6 +62,32 @@ module EventQ
62
62
  def aws_safe_name(name)
63
63
  return name[0..79].gsub(/[^a-zA-Z\d_\-]/,'')
64
64
  end
65
+
66
+ private
67
+
68
+ # Finds the given topic, or returns nil if the topic could not be found
69
+ #
70
+ # @note Responses to list_topics can be paged, so to check *all* topics
71
+ # we'll need to request each page of topics using response.next_token for
72
+ # until the response no longer contains a next_token. Requests to
73
+ # list_topics are throttled to 30 TPS, so in the future we may need to
74
+ # handle this if it becomes a problem.
75
+ #
76
+ # @param topic_name [String] the name of the topic to find
77
+ # @return [String]
78
+ def find_topic(topic_name)
79
+ response = sns.list_topics
80
+ topics = response.topics
81
+ arn = topics.detect { |topic| topic.topic_arn.end_with?(":#{topic_name}") }&.topic_arn
82
+
83
+ while arn.nil? && response.next_token
84
+ response = sns.list_topics(next_token: response.next_token)
85
+ topics = response.topics
86
+ arn = topics.detect { |topic| topic.topic_arn.end_with?(":#{topic_name}") }&.topic_arn
87
+ end
88
+
89
+ arn
90
+ end
65
91
  end
66
92
  end
67
93
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventq
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.2
4
+ version: 2.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - SageOne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-21 00:00:00.000000000 Z
11
+ date: 2020-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler