hanami-events-cloud_pubsub 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +3 -0
- data/lib/hanami/events/adapter/cloud_pubsub.rb +6 -5
- data/lib/hanami/events/cloud_pubsub.rb +3 -0
- data/lib/hanami/events/cloud_pubsub/errors.rb +14 -0
- data/lib/hanami/events/cloud_pubsub/listener.rb +3 -6
- data/lib/hanami/events/cloud_pubsub/middleware/auto_retry.rb +14 -7
- data/lib/hanami/events/cloud_pubsub/middleware/stack.rb +4 -4
- data/lib/hanami/events/cloud_pubsub/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 639fa55622e6b2d507f561c134d807559f514262fa046e853bac4c0ba6b9af1d
|
4
|
+
data.tar.gz: 61fe66adcaf2b93d19ba8b45f5aae9c0fed36820f75336e43ecb9d9d903796cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 667da0f37844d1101ad21e9ff32dccee22785a22deecb149bb068428d3a9af971dd017346df762ca4b3fb5ed4bd44acf00023e77f15b5720d43c9b7bc013bd72
|
7
|
+
data.tar.gz: 94c662671929bc356a0b7d4f9dec885b0916fa49d0205bb4bc092b40111b9e67d69a593987014316ff807c30a18baa254e9adc1fa652cc0489baf0c374bd0092
|
data/Gemfile.lock
CHANGED
@@ -8,7 +8,7 @@ GIT
|
|
8
8
|
PATH
|
9
9
|
remote: .
|
10
10
|
specs:
|
11
|
-
hanami-events-cloud_pubsub (2.
|
11
|
+
hanami-events-cloud_pubsub (2.1.0)
|
12
12
|
dry-configurable (~> 0.8.0)
|
13
13
|
google-cloud-pubsub (~> 0.34.0)
|
14
14
|
hanami-cli (>= 0.2.0)
|
@@ -49,7 +49,7 @@ GEM
|
|
49
49
|
googleauth (>= 0.6.2, < 0.10.0)
|
50
50
|
grpc (>= 1.7.2, < 2.0)
|
51
51
|
rly (~> 0.2.3)
|
52
|
-
google-protobuf (3.7.0)
|
52
|
+
google-protobuf (3.7.0-x86_64-linux)
|
53
53
|
googleapis-common-protos (1.3.8)
|
54
54
|
google-protobuf (~> 3.0)
|
55
55
|
googleapis-common-protos-types (~> 1.0)
|
@@ -63,7 +63,7 @@ GEM
|
|
63
63
|
multi_json (~> 1.11)
|
64
64
|
os (>= 0.9, < 2.0)
|
65
65
|
signet (~> 0.7)
|
66
|
-
grpc (1.19.0)
|
66
|
+
grpc (1.19.0-x86_64-linux)
|
67
67
|
google-protobuf (~> 3.1)
|
68
68
|
googleapis-common-protos-types (~> 1.0.0)
|
69
69
|
grpc-google-iam-v1 (0.6.9)
|
data/README.md
CHANGED
@@ -30,6 +30,9 @@ Hanami.configure do
|
|
30
30
|
config.pubsub = { project_id: 'emulator' } # optional
|
31
31
|
config.logger = Hanami.logger # optional
|
32
32
|
config.namespace = :staging # optional
|
33
|
+
config.auto_create_topics = false # optional
|
34
|
+
config.auto_create_subscriptions = false # optional
|
35
|
+
config.error_handlers << ->(err, message) { MyErrorReporter.report(err) }
|
33
36
|
# ...
|
34
37
|
end
|
35
38
|
end
|
@@ -93,11 +93,12 @@ module Hanami
|
|
93
93
|
@serializer ||= Hanami::Events::Serializer[@serializer_type].new
|
94
94
|
end
|
95
95
|
|
96
|
-
def topic_for(
|
97
|
-
@topic_registry[
|
98
|
-
|
99
|
-
|
100
|
-
|
96
|
+
def topic_for(name)
|
97
|
+
@topic_registry[name.to_s] ||= begin
|
98
|
+
@pubsub.find_topic(name) ||
|
99
|
+
(CloudPubsub.auto_create_topics && @pubsub.create_topic(name)) ||
|
100
|
+
raise(CloudPubsub::Errors::TopicNotFoundError, "no topic named: #{name}")
|
101
|
+
end
|
101
102
|
end
|
102
103
|
|
103
104
|
def namespaced(val, sep: '.')
|
@@ -7,6 +7,7 @@ require 'hanami/events/cloud_pubsub/middleware/stack'
|
|
7
7
|
require 'hanami/events/cloud_pubsub/middleware/logging'
|
8
8
|
require 'hanami/events/cloud_pubsub/middleware/auto_retry'
|
9
9
|
require 'hanami/events/cloud_pubsub/runner'
|
10
|
+
require 'hanami/events/cloud_pubsub/errors'
|
10
11
|
require 'google/cloud/pubsub'
|
11
12
|
require 'dry-configurable'
|
12
13
|
|
@@ -31,6 +32,8 @@ module Hanami
|
|
31
32
|
end
|
32
33
|
|
33
34
|
setting :project_id, reader: true
|
35
|
+
setting :auto_create_subscriptions, false, reader: true
|
36
|
+
setting :auto_create_topics, false, reader: true
|
34
37
|
setting :logger, Logger.new(STDOUT), reader: true
|
35
38
|
setting :subscriptions_loader, proc {
|
36
39
|
abort <<~MSG
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hanami
|
4
|
+
module Events
|
5
|
+
module CloudPubsub
|
6
|
+
# Errors
|
7
|
+
module Errors
|
8
|
+
class Error < StandardError; end
|
9
|
+
class TopicNotFoundError < Error; end
|
10
|
+
class SubscriptionNotFoundError < Error; end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -17,8 +17,6 @@ module Hanami
|
|
17
17
|
:event_name,
|
18
18
|
:subscriber_opts,
|
19
19
|
:middleware
|
20
|
-
|
21
|
-
# rubocop:disable Metrics/ParameterLists
|
22
20
|
def initialize(topic:,
|
23
21
|
logger:,
|
24
22
|
handler:,
|
@@ -34,7 +32,6 @@ module Hanami
|
|
34
32
|
@subscriber_opts = CloudPubsub.config.subscriber.to_h.merge(subscriber_opts)
|
35
33
|
@middleware = middleware
|
36
34
|
end
|
37
|
-
# rubocop:enable Metrics/ParameterLists
|
38
35
|
|
39
36
|
def register
|
40
37
|
subscription = subscription_for(subscriber_id)
|
@@ -90,9 +87,9 @@ module Hanami
|
|
90
87
|
end
|
91
88
|
|
92
89
|
def subscription_for(name)
|
93
|
-
topic.
|
94
|
-
|
95
|
-
|
90
|
+
topic.find_subscription(name) ||
|
91
|
+
(CloudPubsub.auto_create_subscriptions && topic.create_subscription(name)) ||
|
92
|
+
raise(Errors::SubscriptionNotFoundError, "no subscription named: #{name}")
|
96
93
|
end
|
97
94
|
|
98
95
|
def ensure_subscriber!
|
@@ -11,7 +11,7 @@ module Hanami
|
|
11
11
|
@logger = logger
|
12
12
|
end
|
13
13
|
|
14
|
-
def call(message,
|
14
|
+
def call(message, args = {})
|
15
15
|
succeeded = false
|
16
16
|
failed = false
|
17
17
|
yield
|
@@ -20,19 +20,19 @@ module Hanami
|
|
20
20
|
failed = true
|
21
21
|
raise err
|
22
22
|
ensure
|
23
|
-
ack_or_reject(message, succeeded, failed)
|
23
|
+
ack_or_reject(message, succeeded, failed, args)
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
27
27
|
|
28
|
-
def ack_or_reject(message, succeeded, failed)
|
28
|
+
def ack_or_reject(message, succeeded, failed, args)
|
29
29
|
id = message.message_id
|
30
30
|
|
31
31
|
if succeeded
|
32
32
|
message.acknowledge!
|
33
33
|
logger.debug "Message(#{id}) was acknowledged"
|
34
34
|
elsif failed
|
35
|
-
seconds = calculate_backoff_seconds(message)
|
35
|
+
seconds = calculate_backoff_seconds(message, args)
|
36
36
|
success = message.modify_ack_deadline!(seconds)
|
37
37
|
msg = "added #{success ? seconds : 0} seconds of delay to ack deadline"
|
38
38
|
logger.debug "Message(#{id}) failed, #{msg}" if success
|
@@ -46,9 +46,16 @@ module Hanami
|
|
46
46
|
@logger || CloudPubsub.logger
|
47
47
|
end
|
48
48
|
|
49
|
-
def calculate_backoff_seconds(_message)
|
50
|
-
|
51
|
-
|
49
|
+
def calculate_backoff_seconds(_message, args)
|
50
|
+
amt = if args.key?(:attempts)
|
51
|
+
count = args[:attempts]
|
52
|
+
# min + exponential + random smear
|
53
|
+
15 + count**4 + (rand(30) * (count + 1))
|
54
|
+
else
|
55
|
+
60
|
56
|
+
end
|
57
|
+
|
58
|
+
amt > 600 ? 600 : amt
|
52
59
|
end
|
53
60
|
end
|
54
61
|
end
|
@@ -40,14 +40,14 @@ module Hanami
|
|
40
40
|
@entries.shift
|
41
41
|
end
|
42
42
|
|
43
|
-
def invoke(*
|
43
|
+
def invoke(*base_args)
|
44
44
|
stack = entries.dup
|
45
45
|
|
46
|
-
traverse_stack = lambda do
|
46
|
+
traverse_stack = lambda do |*args|
|
47
47
|
if stack.empty?
|
48
|
-
yield(*args)
|
48
|
+
yield(*base_args, *args)
|
49
49
|
else
|
50
|
-
stack.shift.call(*args, &traverse_stack)
|
50
|
+
stack.shift.call(*base_args, *args, &traverse_stack)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-events-cloud_pubsub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Ker-Seymer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- lib/hanami/events/adapter/cloud_pubsub.rb
|
139
139
|
- lib/hanami/events/cloud_pubsub.rb
|
140
140
|
- lib/hanami/events/cloud_pubsub/cli.rb
|
141
|
+
- lib/hanami/events/cloud_pubsub/errors.rb
|
141
142
|
- lib/hanami/events/cloud_pubsub/handler.rb
|
142
143
|
- lib/hanami/events/cloud_pubsub/health_check_server.rb
|
143
144
|
- lib/hanami/events/cloud_pubsub/integration.rb
|