hanami-events-cloud_pubsub 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hanami/events/adapter/cloud_pubsub.rb +5 -4
- data/lib/hanami/events/cloud_pubsub.rb +2 -2
- data/lib/hanami/events/cloud_pubsub/cli.rb +3 -2
- data/lib/hanami/events/cloud_pubsub/health_check_server.rb +0 -1
- data/lib/hanami/events/cloud_pubsub/integration.rb +4 -5
- data/lib/hanami/events/cloud_pubsub/listener.rb +3 -1
- data/lib/hanami/events/cloud_pubsub/middleware/prometheus.rb +16 -2
- data/lib/hanami/events/cloud_pubsub/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce3a1788cccaf44d604f113f700ffe69b2e198d068b6dce7ed25f85bc1c2f72a
|
4
|
+
data.tar.gz: 0cbbe24fb26de4fc989dcfc53f2cb73fccaacc58408deaae623d1d6d7e249ba2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9789652777e1a651533eab9c0f68a418815ce7694b2888e4d6e01ffb0d2b8f5099cea2dbd9903fc6abb8c82b547f7107fcc3ce8356396414baa443335b2bc021
|
7
|
+
data.tar.gz: 585fc1954bc4431f5770f1eb7fb8d659c22f28726e69ecc60bdd4751e9a627de1e2f5321e142a04222a46c03d18d08aa5a6304102d8dd976b48ba0fb09aef770
|
@@ -54,7 +54,7 @@ module Hanami
|
|
54
54
|
# @param id [String] A unique identifier for the subscriber
|
55
55
|
# @param subscriber_opts [String] Additional options for the subscriber
|
56
56
|
# @param block [Block] to execute when event is broadcasted
|
57
|
-
def subscribe(name, id:, **subscriber_opts, &block)
|
57
|
+
def subscribe(name, id:, auto_ack: true, **subscriber_opts, &block)
|
58
58
|
event_name = namespaced(name)
|
59
59
|
namespaced_id = namespaced(id)
|
60
60
|
|
@@ -64,7 +64,7 @@ module Hanami
|
|
64
64
|
@subscribers << sub
|
65
65
|
topic = topic_for event_name
|
66
66
|
|
67
|
-
register_listener(event_name, topic, namespaced_id, subscriber_opts)
|
67
|
+
register_listener(event_name, topic, namespaced_id, auto_ack, subscriber_opts)
|
68
68
|
end
|
69
69
|
|
70
70
|
def flush_messages
|
@@ -76,7 +76,7 @@ module Hanami
|
|
76
76
|
|
77
77
|
attr_reader :logger
|
78
78
|
|
79
|
-
def register_listener(event_name, topic, subscriber_id, subscriber_opts)
|
79
|
+
def register_listener(event_name, topic, subscriber_id, auto_ack, subscriber_opts)
|
80
80
|
listener = ::Hanami::Events::CloudPubsub::Listener.new(
|
81
81
|
subscriber_id: subscriber_id,
|
82
82
|
event_name: event_name,
|
@@ -84,7 +84,8 @@ module Hanami
|
|
84
84
|
logger: logger,
|
85
85
|
topic: topic,
|
86
86
|
subscriber_opts: subscriber_opts,
|
87
|
-
dead_letter_topic: dead_letter_topic
|
87
|
+
dead_letter_topic: dead_letter_topic,
|
88
|
+
auto_ack: auto_ack
|
88
89
|
)
|
89
90
|
|
90
91
|
@listeners << listener
|
@@ -7,7 +7,6 @@ require 'hanami/events/cloud_pubsub/middleware/stack'
|
|
7
7
|
require 'hanami/events/cloud_pubsub/middleware/logging'
|
8
8
|
require 'hanami/events/cloud_pubsub/runner'
|
9
9
|
require 'hanami/events/cloud_pubsub/errors'
|
10
|
-
require 'google/cloud/pubsub'
|
11
10
|
require 'dry-configurable'
|
12
11
|
|
13
12
|
module Hanami
|
@@ -63,7 +62,7 @@ module Hanami
|
|
63
62
|
if defined?(Yabeda::Prometheus::Exporter)
|
64
63
|
begin
|
65
64
|
require 'hanami/events/cloud_pubsub/middleware/prometheus'
|
66
|
-
middleware_stack
|
65
|
+
middleware_stack << Middleware::Prometheus.new
|
67
66
|
rescue LoadError
|
68
67
|
# ok
|
69
68
|
end
|
@@ -97,6 +96,7 @@ module Hanami
|
|
97
96
|
end
|
98
97
|
|
99
98
|
def self.finalize_settings!
|
99
|
+
require 'google/cloud/pubsub'
|
100
100
|
conf_hash = config.pubsub
|
101
101
|
conf_hash.each { |key, val| Google::Cloud::Pubsub.configure[key] = val }
|
102
102
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'hanami/cli'
|
4
|
-
require 'hanami/events/cloud_pubsub'
|
5
|
-
require 'hanami/events/cloud_pubsub/health_check_server'
|
6
4
|
|
7
5
|
module Hanami
|
8
6
|
module Events
|
@@ -55,6 +53,7 @@ module Hanami
|
|
55
53
|
end
|
56
54
|
|
57
55
|
def start_server
|
56
|
+
require 'hanami/events/cloud_pubsub/health_check_server'
|
58
57
|
server = HealthCheckServer.new(runner, logger)
|
59
58
|
on_shutdown = proc { @event_queue << proc { shutdown } }
|
60
59
|
server.run_in_background(on_shutdown: on_shutdown)
|
@@ -77,6 +76,7 @@ module Hanami
|
|
77
76
|
def start_runner
|
78
77
|
logger.debug 'Running in emulator mode' if @emulator
|
79
78
|
logger.info "Starting worker (pid: #{Process.pid})"
|
79
|
+
GC.compact if GC.respond_to?(:compact)
|
80
80
|
runner.start
|
81
81
|
end
|
82
82
|
|
@@ -86,6 +86,7 @@ module Hanami
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def build_runner
|
89
|
+
require 'hanami/events/cloud_pubsub'
|
89
90
|
Hanami::Components.resolve 'events'
|
90
91
|
events = Hanami::Components['events']
|
91
92
|
@runner = Runner.new(logger: logger, adapter: events.adapter)
|
@@ -33,11 +33,10 @@ module Hanami
|
|
33
33
|
conf.cloud_pubsub.each { |blk| blk.call(config) }
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
)
|
36
|
+
require 'google/cloud/pubsub'
|
37
|
+
|
38
|
+
opts = { pubsub: Google::Cloud::Pubsub.new, logger: Hanami::Components['logger'] }
|
39
|
+
::Hanami::Events.initialize(:cloud_pubsub, **opts)
|
41
40
|
end
|
42
41
|
end
|
43
42
|
end
|
@@ -26,6 +26,7 @@ module Hanami
|
|
26
26
|
subscriber_id:,
|
27
27
|
subscriber_opts: {},
|
28
28
|
middleware: CloudPubsub.config.middleware,
|
29
|
+
auto_ack: true,
|
29
30
|
dead_letter_topic: nil)
|
30
31
|
@topic = topic
|
31
32
|
@logger = logger
|
@@ -35,6 +36,7 @@ module Hanami
|
|
35
36
|
@input_subscriber_opts = subscriber_opts
|
36
37
|
@middleware = middleware
|
37
38
|
@dead_letter_topic = dead_letter_topic
|
39
|
+
@auto_ack = auto_ack
|
38
40
|
end
|
39
41
|
# rubocop:enable Metrics/ParameterLists
|
40
42
|
|
@@ -86,7 +88,7 @@ module Hanami
|
|
86
88
|
|
87
89
|
def run_handler(message)
|
88
90
|
middleware.invoke(message) { handler.call(message) }
|
89
|
-
message.ack!
|
91
|
+
message.ack! if @auto_ack
|
90
92
|
rescue StandardError => e
|
91
93
|
run_error_handlers(e, message.message_id.to_s)
|
92
94
|
message.nack! if CloudPubsub.config.auto_retry.enabled
|
@@ -6,15 +6,27 @@ module Hanami
|
|
6
6
|
module Middleware
|
7
7
|
# Middleware used for logging useful information about an event
|
8
8
|
class Prometheus
|
9
|
+
LONG_RUNNING_JOB_RUNTIME_BUCKETS = [
|
10
|
+
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, # standard (from Prometheus)
|
11
|
+
30, 60, 120, 300, 1800, 3600, 21_600 # Tasks may be very long-running
|
12
|
+
].freeze
|
13
|
+
|
9
14
|
Yabeda.configure do
|
10
15
|
counter(
|
11
16
|
:received_pubsub_events,
|
12
17
|
tags: %i[event_name subscription status],
|
13
18
|
comment: 'A counter of received pubsub events'
|
14
19
|
)
|
20
|
+
|
21
|
+
histogram :subscriber_runtime, comment: 'A histogram of the subscriber execution time.',
|
22
|
+
unit: :seconds,
|
23
|
+
per: :message,
|
24
|
+
tags: %i[event_name subscription status],
|
25
|
+
buckets: LONG_RUNNING_JOB_RUNTIME_BUCKETS
|
15
26
|
end
|
16
27
|
|
17
28
|
def call(msg, **opts)
|
29
|
+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
18
30
|
status = :running
|
19
31
|
|
20
32
|
begin
|
@@ -26,16 +38,18 @@ module Hanami
|
|
26
38
|
raise
|
27
39
|
end
|
28
40
|
ensure
|
29
|
-
record_metrics(msg, status)
|
41
|
+
record_metrics(msg, status, start)
|
30
42
|
end
|
31
43
|
|
32
44
|
private
|
33
45
|
|
34
|
-
def record_metrics(msg, status)
|
46
|
+
def record_metrics(msg, status, start)
|
47
|
+
elapsed = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start).round(3)
|
35
48
|
sub = msg.subscription.subscriber.subscription_name
|
36
49
|
event_name = msg.attributes['event_name']
|
37
50
|
labels = { event_name: event_name, subscription: sub, status: status }
|
38
51
|
Yabeda.received_pubsub_events.increment(labels, by: 1)
|
52
|
+
Yabeda.subscriber_runtime.measure(labels, elapsed)
|
39
53
|
rescue StandardError
|
40
54
|
# ok
|
41
55
|
end
|
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: 3.
|
4
|
+
version: 3.2.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: 2021-
|
11
|
+
date: 2021-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|