stenotype 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d77ba29ea50a26b7a8592149629d6a58368b56a615246ebaff36ade2a8a9f3a7
4
- data.tar.gz: d519ef0ee071b97d6ff3dbed088f06b18826adbfdadcddaf89019c230b1aecb3
3
+ metadata.gz: 5f58226124306beb915f76259d055c013e197d24dee87513d751764486ce8033
4
+ data.tar.gz: eee031ad3b4f4b9d5b8ed8645e5d7f676f0490f1f9351cec516ffc72ef5b298a
5
5
  SHA512:
6
- metadata.gz: b59b094ef4c1379a2771f78fef83639040fedc62a0a2d2fb9209c50060e2c96856ea26fd28090a5788a06c4d97942b78c954df1eba861d4fbdd07d675f91d60e
7
- data.tar.gz: dfca37efc78a9063d8a239e27b2ed36a6b2ae981c330b072a2b3b43b46c9359323f4fd1ac790096c1458a38e860519ceb972f84ef9f9e12f2788b77d96c11709
6
+ metadata.gz: fe129ae49b3b255a02f1cadcc6920820348846d0b10dba93ab554322b545401a63c8bce7becd239502e9ff433b127e738ff612d4b1cc9903a0f32212ce68eda1
7
+ data.tar.gz: 275de1f70c2c0f4e9d608e79d93e773d75538b18a47c1f2848a7753bb6151b5f96a8ef7c74b36b3a462360de7be196a247d3be3429cfd7f1b00364691ae01a5e
@@ -2,6 +2,14 @@
2
2
 
3
3
  *Release Date*: 2020/01/13
4
4
 
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
+
5
13
  ### 0.1.5 2020/01/13
6
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.
7
15
  * Adds an `at_exit` hook to flush the async message queue when using the library in async mode.
@@ -96,7 +96,7 @@ GEM
96
96
  googleauth (~> 0.9)
97
97
  grpc (~> 1.24)
98
98
  rly (~> 0.2.3)
99
- google-protobuf (3.11.1-universal-darwin)
99
+ google-protobuf (3.11.1)
100
100
  googleapis-common-protos (1.3.9)
101
101
  google-protobuf (~> 3.0)
102
102
  googleapis-common-protos-types (~> 1.0)
@@ -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.25.0-universal-darwin)
113
+ grpc (1.25.0)
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 = SecureRandom
35
- config.dispatcher = Stenotype::Dispatcher.new
36
- config.logger = Logger.new(STDOUT)
37
- config.graceful_error_handling = true
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
 
@@ -42,6 +42,14 @@ module Stenotype
42
42
  "#{self.class.name} must implement method #publish"
43
43
  end
44
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
+
45
53
  #
46
54
  # This method is expected to be implemented by subclasses. In case async
47
55
  # publisher is used the process might end before the async queue of
@@ -34,12 +34,6 @@ module Stenotype
34
34
  # end
35
35
  #
36
36
  class GoogleCloud < Base
37
- attr_reader :topic
38
-
39
- def initialize(client: nil, topic: nil)
40
- super(client: client)
41
- @topic = topic
42
- end
43
37
  #
44
38
  # @param event_data {Hash} The data to be published to Google Cloud
45
39
  # @raise {Stenotype::MessageNotPublishedError} unless message is published
@@ -72,6 +66,16 @@ module Stenotype
72
66
  topic.async_publisher.stop.wait!
73
67
  end
74
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
+
75
79
  private
76
80
 
77
81
  def publish_sync(event_data, **additional_attrs)
@@ -1,8 +1,10 @@
1
- require 'stenotype'
1
+ # frozen_string_literal: true
2
2
 
3
3
  # :nocov:
4
+ require "stenotype"
5
+
4
6
  at_exit do
5
7
  targets = Stenotype.config.targets
6
8
  targets.each(&:flush!)
7
9
  end
8
- # :nocov:
10
+ # :nocov:
@@ -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: true
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
 
@@ -24,12 +24,12 @@ module Stenotype
24
24
  event = new(name, attributes, eval_context: eval_context, dispatcher: dispatcher)
25
25
  event.emit!
26
26
  event
27
- rescue => error
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(error)
32
+ Stenotype::Configuration.logger.error(exception)
33
33
 
34
34
  raise Stenotype::Error unless Stenotype.config.graceful_error_handling
35
35
  end
@@ -68,12 +68,12 @@ module Stenotype
68
68
 
69
69
  begin
70
70
  dispatcher.publish(self)
71
- rescue => error
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(error)
76
+ Stenotype::Configuration.logger.error(exception)
77
77
 
78
78
  raise Stenotype::Error unless Stenotype.config.graceful_error_handling
79
79
  end
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Stenotype
4
4
  # :nodoc:
5
- VERSION = "0.1.6"
5
+ VERSION = "0.1.7"
6
6
  # :nodoc:
7
7
  end
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.6
4
+ version: 0.1.7
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-17 00:00:00.000000000 Z
11
+ date: 2020-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport