stenotype 0.1.4 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -2
- data/Gemfile.lock +3 -3
- data/README.md +17 -4
- data/lib/stenotype/adapters/base.rb +22 -1
- data/lib/stenotype/adapters/google_cloud.rb +21 -1
- data/lib/stenotype/adapters/stdout_adapter.rb +9 -5
- data/lib/stenotype/at_exit.rb +10 -0
- data/lib/stenotype/configuration.rb +5 -1
- data/lib/stenotype/dispatcher.rb +1 -1
- data/lib/stenotype/event.rb +6 -6
- data/lib/stenotype/railtie.rb +2 -0
- data/lib/stenotype/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: 8b9a863cd51cf75e8d472879bc6a7053f734c2b9081912c332d78de384291c02
|
4
|
+
data.tar.gz: 10c8fca08c07945f3df22cc9a3087c01aa0d65f8e8e3f171b9af678033c7ccb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66a572106095607f8ca784ec38d32d00d13e5930fad9cc27177dff13ef8c3f5489d77e6feea2ac10e8bb1f745a5f23e300d9e597454e87325c0fea7695144ea3
|
7
|
+
data.tar.gz: 743b0866dca96eea731df808875bdae9a601255bb146a7d9446b8740e902a3d0fa1065e3a08290dba34c38e95203960f09bad517fdbeaa903e1d7ef76b681244
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,23 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
*Release Date*: 2020/01/
|
3
|
+
*Release Date*: 2020/01/13
|
4
4
|
|
5
|
-
### 0.1.
|
5
|
+
### 0.1.7 2020/01/20
|
6
|
+
* Adds a config option to allow explicit adapter setup.
|
7
|
+
* Adds an `after_initialize` rails hook to setup adapters.
|
8
|
+
* Remove topic from the list of Google Cloud adapter arguments.
|
9
|
+
|
10
|
+
### 0.1.6 2020/01/17
|
11
|
+
* Allow topic to be explicitly set upon Google Cloud adapter initialization
|
12
|
+
|
13
|
+
### 0.1.5 2020/01/13
|
14
|
+
* In case `graceful_error_handling` is set to off raise a generic `Stenotype::Error` on any exception in order to intercept a single error type in the client code.
|
15
|
+
* Adds an `at_exit` hook to flush the async message queue when using the library in async mode.
|
16
|
+
|
17
|
+
### 0.1.4 2020/01/10
|
6
18
|
* Adds a new configuration option `graceful_error_handling` to suppress errors raised from the gem's internals yet logging the error to specified `config.logger`
|
19
|
+
|
20
|
+
### 0.1.3: 2020/01/10
|
7
21
|
* Adds a new configuration option `logger` to use during error handling
|
8
22
|
* Adds a new config option `Stenotype.config.enabled`. If the option is set to false then event is not going to be published. The option is `true` by default.
|
9
23
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stenotype (0.1.
|
4
|
+
stenotype (0.1.9)
|
5
5
|
activesupport (>= 5.0.0)
|
6
6
|
google-cloud-pubsub (~> 1.0.0)
|
7
7
|
spicery (>= 0.19.0, < 1.0)
|
@@ -75,7 +75,7 @@ GEM
|
|
75
75
|
tablesalt (= 0.19.2)
|
76
76
|
faker (1.9.6)
|
77
77
|
i18n (>= 0.7)
|
78
|
-
faraday (0.17.
|
78
|
+
faraday (0.17.3)
|
79
79
|
multipart-post (>= 1.2, < 3)
|
80
80
|
github-markup (3.0.4)
|
81
81
|
globalid (0.4.2)
|
@@ -110,7 +110,7 @@ GEM
|
|
110
110
|
multi_json (~> 1.11)
|
111
111
|
os (>= 0.9, < 2.0)
|
112
112
|
signet (~> 0.12)
|
113
|
-
grpc (1.
|
113
|
+
grpc (1.26.0-universal-darwin)
|
114
114
|
google-protobuf (~> 3.8)
|
115
115
|
googleapis-common-protos-types (~> 1.0)
|
116
116
|
grpc-google-iam-v1 (0.6.9)
|
data/README.md
CHANGED
@@ -31,10 +31,11 @@ Stenotype.configure do |config|
|
|
31
31
|
Stenotype::Adapters::GoogleCloud.new
|
32
32
|
]
|
33
33
|
|
34
|
-
config.uuid_generator
|
35
|
-
config.dispatcher
|
36
|
-
config.logger
|
37
|
-
config.graceful_error_handling
|
34
|
+
config.uuid_generator = SecureRandom
|
35
|
+
config.dispatcher = Stenotype::Dispatcher.new
|
36
|
+
config.logger = Logger.new(STDOUT)
|
37
|
+
config.graceful_error_handling = true
|
38
|
+
config.auto_adapter_initialization = true
|
38
39
|
|
39
40
|
config.google_cloud do |gc_config|
|
40
41
|
gc_config.project_id = "google_cloud_project_id"
|
@@ -98,6 +99,10 @@ Allows to enable/disable Rails ActionController extension
|
|
98
99
|
|
99
100
|
Allows to enable/disable Rails ActiveJob extension
|
100
101
|
|
102
|
+
#### config.rails.auto_adapter_initialization
|
103
|
+
|
104
|
+
Controls whether the hook `auto_initialize!` is run for each adapter. If set to true `auto_initialize!` is invoked for every adapter. If false `auto_initialize!` is not run. For example for google cloud adapter this will instantiate `client` and `topic` objects before first publish. If set to false `client` and `topic` are lazy initialized.
|
105
|
+
|
101
106
|
#### Configuring context handlers
|
102
107
|
|
103
108
|
Each event is emitted in a context which might be an ActionController instance or an ActiveJob instance or potentially any other place. Context handlers are implemented as plain ruby classes, so before using them you must register them. By default a plain `Class` handler is registered when not used with any framework. In case Ruby on Rails is used, then there are two additional context handlers for `ActionController` and `ActiveJob` instances.
|
@@ -228,6 +233,14 @@ class CustomAdapter < Stenotype::Adapters::Base
|
|
228
233
|
def publish(event_data, **additional_arguments)
|
229
234
|
# custom publishing logic
|
230
235
|
end
|
236
|
+
|
237
|
+
def flush!
|
238
|
+
# actions to be taken to flush the messages
|
239
|
+
end
|
240
|
+
|
241
|
+
def auto_initialize!
|
242
|
+
# actions to be taken to setup internal adapter state (client, endpoint, whatsoever)
|
243
|
+
end
|
231
244
|
end
|
232
245
|
```
|
233
246
|
|
@@ -35,12 +35,33 @@ module Stenotype
|
|
35
35
|
#
|
36
36
|
# This method is expected to be implemented by subclasses
|
37
37
|
# @abstract
|
38
|
-
# @raise
|
38
|
+
# @raise {NotImplementedError} unless implemented in a subclass
|
39
39
|
#
|
40
40
|
def publish(_event_data, **_additional_attrs)
|
41
41
|
raise NotImplementedError,
|
42
42
|
"#{self.class.name} must implement method #publish"
|
43
43
|
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Allows custom setup of the adapter. Noop by default
|
47
|
+
# @abstract
|
48
|
+
#
|
49
|
+
def auto_initialize!
|
50
|
+
# noop by default
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# This method is expected to be implemented by subclasses. In case async
|
55
|
+
# publisher is used the process might end before the async queue of
|
56
|
+
# messages is processed, so this method is going to be used in a
|
57
|
+
# `at_exit` hook to flush the queue.
|
58
|
+
# @abstract
|
59
|
+
# @raise {NotImplementedError} unless implemented in a subclass
|
60
|
+
#
|
61
|
+
def flush!
|
62
|
+
raise NotImplementedError,
|
63
|
+
"#{self.class.name} must implement method #flush"
|
64
|
+
end
|
44
65
|
end
|
45
66
|
end
|
46
67
|
end
|
@@ -35,7 +35,7 @@ module Stenotype
|
|
35
35
|
#
|
36
36
|
class GoogleCloud < Base
|
37
37
|
#
|
38
|
-
# @param event_data {
|
38
|
+
# @param event_data {String} The data to be published to Google Cloud
|
39
39
|
# @raise {Stenotype::MessageNotPublishedError} unless message is published
|
40
40
|
#
|
41
41
|
# @example With default client
|
@@ -56,6 +56,26 @@ module Stenotype
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
#
|
60
|
+
# Flushes the topic's async queue
|
61
|
+
#
|
62
|
+
def flush!
|
63
|
+
# a publisher might be uninitialized until the first event is published
|
64
|
+
return unless topic.async_publisher
|
65
|
+
|
66
|
+
topic.async_publisher.stop.wait!
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# If not called both client and topic are lazy initialized on first call (if not
|
71
|
+
# passed to #initialize). #auto_initialize! is going to explicitly initialize
|
72
|
+
# both client and topic.
|
73
|
+
#
|
74
|
+
def auto_initialize!
|
75
|
+
client
|
76
|
+
topic
|
77
|
+
end
|
78
|
+
|
59
79
|
private
|
60
80
|
|
61
81
|
def publish_sync(event_data, **additional_attrs)
|
@@ -21,7 +21,7 @@ module Stenotype
|
|
21
21
|
#
|
22
22
|
class StdoutAdapter < Base
|
23
23
|
#
|
24
|
-
# @param event_data {
|
24
|
+
# @param event_data {Sting} The data to be published to STDOUT
|
25
25
|
#
|
26
26
|
# @example Publishing to default client (STDOUT)
|
27
27
|
# adapter = Stenotype::Adapters::StdoutAdapter.new
|
@@ -33,13 +33,17 @@ module Stenotype
|
|
33
33
|
#
|
34
34
|
def publish(event_data, **additional_attrs)
|
35
35
|
client.info("[Stenotype::Event] emitted with the following attributes") do
|
36
|
-
{
|
37
|
-
**event_data,
|
38
|
-
**additional_attrs,
|
39
|
-
}
|
36
|
+
"MESSAGE BODY: #{event_data}, MESSAGE ATTRIBUTES #{additional_attrs.to_json}"
|
40
37
|
end
|
41
38
|
end
|
42
39
|
|
40
|
+
#
|
41
|
+
# Does nothing
|
42
|
+
#
|
43
|
+
def flush!
|
44
|
+
# noop
|
45
|
+
end
|
46
|
+
|
43
47
|
private
|
44
48
|
|
45
49
|
def client
|
@@ -35,6 +35,9 @@ module Stenotype
|
|
35
35
|
# @!attribute enabled
|
36
36
|
# @return {true, false} a flag indicating whether event emission is enabled
|
37
37
|
|
38
|
+
# @!attribute auto_adapter_initialization
|
39
|
+
# @return {true, false} enables/disables lazy initialization of adapters' clients
|
40
|
+
|
38
41
|
# @!attribute targets
|
39
42
|
# @return {Array<#publish>} a list of targets responding to method [#publish]
|
40
43
|
|
@@ -59,7 +62,6 @@ module Stenotype
|
|
59
62
|
# @!attribute [rw] google_cloud.async
|
60
63
|
# @return [true, false] GC publish mode, either async if true, sync if false
|
61
64
|
|
62
|
-
|
63
65
|
# @!attribute [rw] rails
|
64
66
|
# @return [NestedConfiguration] Rails configuration.
|
65
67
|
|
@@ -87,6 +89,7 @@ module Stenotype
|
|
87
89
|
nested :rails do
|
88
90
|
option :enable_action_controller_ext, default: true
|
89
91
|
option :enable_active_job_ext, default: true
|
92
|
+
option :auto_adapter_initialization, default: false
|
90
93
|
end
|
91
94
|
end
|
92
95
|
|
@@ -110,6 +113,7 @@ module Stenotype
|
|
110
113
|
#
|
111
114
|
def logger
|
112
115
|
return config.logger if config.logger
|
116
|
+
|
113
117
|
config.logger || Logger.new(STDOUT)
|
114
118
|
end
|
115
119
|
|
data/lib/stenotype/dispatcher.rb
CHANGED
data/lib/stenotype/event.rb
CHANGED
@@ -24,14 +24,14 @@ module Stenotype
|
|
24
24
|
event = new(name, attributes, eval_context: eval_context, dispatcher: dispatcher)
|
25
25
|
event.emit!
|
26
26
|
event
|
27
|
-
rescue =>
|
27
|
+
rescue StandardError => exception
|
28
28
|
#
|
29
29
|
# @todo This is a temporary solution to enable conditional logger fetching
|
30
30
|
# needs a fix to use default Spicerack::Configuration functionality
|
31
31
|
#
|
32
|
-
Stenotype::Configuration.logger.error(
|
32
|
+
Stenotype::Configuration.logger.error(exception)
|
33
33
|
|
34
|
-
raise unless Stenotype.config.graceful_error_handling
|
34
|
+
raise Stenotype::Error unless Stenotype.config.graceful_error_handling
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -68,14 +68,14 @@ module Stenotype
|
|
68
68
|
|
69
69
|
begin
|
70
70
|
dispatcher.publish(self)
|
71
|
-
rescue =>
|
71
|
+
rescue StandardError => exception
|
72
72
|
#
|
73
73
|
# @todo This is a temporary solution to enable conditional logger fetching
|
74
74
|
# needs a fix to use default Spicerack::Configuration functionality
|
75
75
|
#
|
76
|
-
Stenotype::Configuration.logger.error(
|
76
|
+
Stenotype::Configuration.logger.error(exception)
|
77
77
|
|
78
|
-
raise unless Stenotype.config.graceful_error_handling
|
78
|
+
raise Stenotype::Error unless Stenotype.config.graceful_error_handling
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
data/lib/stenotype/railtie.rb
CHANGED
@@ -18,6 +18,8 @@ module Stenotype
|
|
18
18
|
|
19
19
|
config.stenotype = Stenotype.config
|
20
20
|
|
21
|
+
config.after_initialize { config.stenotype.targets.each(&:auto_initialize!) } if config.stenotype.rails.auto_adapter_initialization
|
22
|
+
|
21
23
|
if config.stenotype.rails.enable_action_controller_ext
|
22
24
|
ActiveSupport.on_load(:action_controller) do
|
23
25
|
Stenotype::ContextHandlers.register Stenotype::ContextHandlers::Rails::Controller
|
data/lib/stenotype/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stenotype
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Kapitonov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -267,6 +267,7 @@ files:
|
|
267
267
|
- lib/stenotype/adapters/base.rb
|
268
268
|
- lib/stenotype/adapters/google_cloud.rb
|
269
269
|
- lib/stenotype/adapters/stdout_adapter.rb
|
270
|
+
- lib/stenotype/at_exit.rb
|
270
271
|
- lib/stenotype/configuration.rb
|
271
272
|
- lib/stenotype/context_handlers.rb
|
272
273
|
- lib/stenotype/context_handlers/base.rb
|