eventboss 1.3.5 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +12 -12
- data/README.md +34 -3
- data/lib/eventboss.rb +1 -0
- data/lib/eventboss/configuration.rb +5 -0
- data/lib/eventboss/error_handlers/db_connection_not_established_handler.rb +11 -0
- data/lib/eventboss/extensions.rb +1 -0
- data/lib/eventboss/middleware.rb +57 -0
- data/lib/eventboss/version.rb +1 -1
- data/lib/eventboss/worker.rb +11 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e7d223c4834db900777f804ac21d03e023e952fa2df455d90768d845cc806e1
|
4
|
+
data.tar.gz: bcc796c5866521aeea6a33c2920ab1634956e5f3b5aeb367c81a17b657df19a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c84d52bb6344340c0cc17f8e7387db07e1a46fa1eb5d04b67d9d577e879ddc294fa71c150e0c3110244ee046a278e3fd43c855e3bd28f31e0477c01e8c5c8603
|
7
|
+
data.tar.gz: de26d5a46fe898d785edc6cd3a3436a75350907c10bf3ac3fd3d2bb9366c390776372dc9b39475cab57529df0c5aaf6df01c6ce1575043f5d947f806b8d056dc
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [1.4.0] - 2020-04-18
|
8
|
+
|
9
|
+
- Introduce server middlewares (#31)
|
10
|
+
|
7
11
|
## [1.1.0] - 2019-07-16
|
8
12
|
|
9
13
|
### Added
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
eventboss (1.
|
4
|
+
eventboss (1.4.1)
|
5
5
|
aws-sdk-sns (>= 1.1.0)
|
6
6
|
aws-sdk-sqs (>= 1.3.0)
|
7
7
|
dotenv (~> 2.1, >= 2.1.1)
|
@@ -9,23 +9,23 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
aws-eventstream (1.0
|
13
|
-
aws-partitions (1.
|
14
|
-
aws-sdk-core (3.
|
15
|
-
aws-eventstream (~> 1
|
12
|
+
aws-eventstream (1.1.0)
|
13
|
+
aws-partitions (1.350.0)
|
14
|
+
aws-sdk-core (3.104.3)
|
15
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
16
16
|
aws-partitions (~> 1, >= 1.239.0)
|
17
17
|
aws-sigv4 (~> 1.1)
|
18
18
|
jmespath (~> 1.0)
|
19
|
-
aws-sdk-sns (1.
|
20
|
-
aws-sdk-core (~> 3, >= 3.
|
19
|
+
aws-sdk-sns (1.28.0)
|
20
|
+
aws-sdk-core (~> 3, >= 3.99.0)
|
21
21
|
aws-sigv4 (~> 1.1)
|
22
|
-
aws-sdk-sqs (1.
|
23
|
-
aws-sdk-core (~> 3, >= 3.
|
22
|
+
aws-sdk-sqs (1.30.0)
|
23
|
+
aws-sdk-core (~> 3, >= 3.99.0)
|
24
24
|
aws-sigv4 (~> 1.1)
|
25
|
-
aws-sigv4 (1.
|
26
|
-
aws-eventstream (~> 1
|
25
|
+
aws-sigv4 (1.2.1)
|
26
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
27
27
|
diff-lcs (1.3)
|
28
|
-
dotenv (2.7.
|
28
|
+
dotenv (2.7.6)
|
29
29
|
jmespath (1.4.0)
|
30
30
|
rake (13.0.1)
|
31
31
|
rspec (3.7.0)
|
data/README.md
CHANGED
@@ -151,13 +151,45 @@ Eventboss.configure do |config|
|
|
151
151
|
end
|
152
152
|
```
|
153
153
|
|
154
|
-
|
154
|
+
### Middlewares
|
155
|
+
|
156
|
+
Server middlewares intercept the execution of your `Listeners`. You can use to extract and run common functions on every message received.
|
157
|
+
|
158
|
+
Define a middleware in the following way:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
class LogMiddleware < Eventboss::Middleware::Base
|
162
|
+
def call(_work)
|
163
|
+
yield
|
164
|
+
logger.debug 'finished with success'
|
165
|
+
rescue StandardError => _error
|
166
|
+
logger.error 'finished with error'
|
167
|
+
raise
|
168
|
+
end
|
169
|
+
|
170
|
+
private
|
171
|
+
|
172
|
+
def logger
|
173
|
+
@logger ||= @options.fetch(:logger)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
```
|
177
|
+
|
178
|
+
And configure your logger as such:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
Eventboss.configure do |config|
|
182
|
+
config.server_middleware.add LogMiddleware, logger: Logger.new
|
183
|
+
end
|
184
|
+
```
|
185
|
+
|
186
|
+
## Development mode
|
155
187
|
|
156
188
|
In the _development mode_ you don't need to create the infrastructure required by the application - Eventboss will take care of this.
|
157
189
|
|
158
190
|
It works on AWS and [localstack](https://github.com/localstack/localstack).
|
159
191
|
|
160
|
-
Following resources are created:
|
192
|
+
Following resources are created:
|
161
193
|
* SNS topics - created when application starts and when message is published
|
162
194
|
* SQS queues (with SendMessage policy) - created when application starts
|
163
195
|
* subscriptions for topics and queues - created when application starts
|
@@ -206,4 +238,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/AirHel
|
|
206
238
|
## License
|
207
239
|
|
208
240
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
209
|
-
|
data/lib/eventboss.rb
CHANGED
@@ -34,6 +34,7 @@ module Eventboss
|
|
34
34
|
defined_or_default('error_handlers') do
|
35
35
|
[ErrorHandlers::Logger.new].tap do |handlers|
|
36
36
|
handlers << ErrorHandlers::DbConnectionDropHandler.new if defined?(::ActiveRecord::StatementInvalid)
|
37
|
+
handlers << ErrorHandlers::DbConnectionNotEstablishedHandler.new if defined?(::ActiveRecord::ConnectionNotEstablished)
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
@@ -118,6 +119,10 @@ module Eventboss
|
|
118
119
|
end
|
119
120
|
end
|
120
121
|
|
122
|
+
def server_middleware
|
123
|
+
@server_middleware ||= Middleware::Chain.new
|
124
|
+
end
|
125
|
+
|
121
126
|
private
|
122
127
|
|
123
128
|
def defined_or_default(variable_name)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Eventboss
|
2
|
+
module ErrorHandlers
|
3
|
+
class DbConnectionNotEstablishedHandler
|
4
|
+
def call(exception, _context = {})
|
5
|
+
if exception.class == ::ActiveRecord::ConnectionNotEstablished
|
6
|
+
::ActiveRecord::Base.connection.reconnect!
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/eventboss/extensions.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Eventboss
|
2
|
+
module Middleware
|
3
|
+
class Chain
|
4
|
+
attr_reader :entries
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@entries = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def add(klass, options = {})
|
11
|
+
@entries << Entry.new(klass, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def invoke(*args)
|
15
|
+
chain = @entries.map(&:build).reverse!
|
16
|
+
|
17
|
+
invoke_lambda = lambda do
|
18
|
+
if (mid = chain.pop)
|
19
|
+
mid.call(*args, &invoke_lambda)
|
20
|
+
else
|
21
|
+
yield
|
22
|
+
end
|
23
|
+
end
|
24
|
+
invoke_lambda.call
|
25
|
+
end
|
26
|
+
|
27
|
+
def clear
|
28
|
+
@entries.clear
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Base
|
33
|
+
attr_reader :options
|
34
|
+
|
35
|
+
def initialize(options)
|
36
|
+
@options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def call
|
40
|
+
raise 'Not implemented'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Entry
|
45
|
+
attr_reader :klass, :options
|
46
|
+
|
47
|
+
def initialize(klass, options)
|
48
|
+
@klass = klass
|
49
|
+
@options = options
|
50
|
+
end
|
51
|
+
|
52
|
+
def build
|
53
|
+
@klass.new(options)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/eventboss/version.rb
CHANGED
data/lib/eventboss/worker.rb
CHANGED
@@ -20,7 +20,7 @@ module Eventboss
|
|
20
20
|
|
21
21
|
def run
|
22
22
|
while (work = @bus.pop)
|
23
|
-
work
|
23
|
+
run_work(work)
|
24
24
|
end
|
25
25
|
@launcher.worker_stopped(self)
|
26
26
|
rescue Eventboss::Shutdown
|
@@ -32,6 +32,12 @@ module Eventboss
|
|
32
32
|
@launcher.worker_stopped(self, restart: true)
|
33
33
|
end
|
34
34
|
|
35
|
+
def run_work(work)
|
36
|
+
server_middleware.invoke(work) do
|
37
|
+
work.run
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
35
41
|
def terminate(wait = false)
|
36
42
|
stop_token
|
37
43
|
return unless @thread
|
@@ -51,5 +57,9 @@ module Eventboss
|
|
51
57
|
def stop_token
|
52
58
|
@bus << nil
|
53
59
|
end
|
60
|
+
|
61
|
+
def server_middleware
|
62
|
+
Eventboss.configuration.server_middleware
|
63
|
+
end
|
54
64
|
end
|
55
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventboss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AirHelp
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-sqs
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/eventboss/development_mode.rb
|
127
127
|
- lib/eventboss/error_handlers/airbrake.rb
|
128
128
|
- lib/eventboss/error_handlers/db_connection_drop_handler.rb
|
129
|
+
- lib/eventboss/error_handlers/db_connection_not_established_handler.rb
|
129
130
|
- lib/eventboss/error_handlers/logger.rb
|
130
131
|
- lib/eventboss/extensions.rb
|
131
132
|
- lib/eventboss/fetcher.rb
|
@@ -134,6 +135,7 @@ files:
|
|
134
135
|
- lib/eventboss/listener.rb
|
135
136
|
- lib/eventboss/logging.rb
|
136
137
|
- lib/eventboss/long_poller.rb
|
138
|
+
- lib/eventboss/middleware.rb
|
137
139
|
- lib/eventboss/publisher.rb
|
138
140
|
- lib/eventboss/queue.rb
|
139
141
|
- lib/eventboss/queue_listener.rb
|
@@ -154,7 +156,7 @@ homepage: https://github.com/AirHelp/eventboss
|
|
154
156
|
licenses:
|
155
157
|
- MIT
|
156
158
|
metadata: {}
|
157
|
-
post_install_message:
|
159
|
+
post_install_message:
|
158
160
|
rdoc_options: []
|
159
161
|
require_paths:
|
160
162
|
- lib
|
@@ -170,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
172
|
version: '0'
|
171
173
|
requirements: []
|
172
174
|
rubygems_version: 3.0.3
|
173
|
-
signing_key:
|
175
|
+
signing_key:
|
174
176
|
specification_version: 4
|
175
177
|
summary: Eventboss Ruby Client.
|
176
178
|
test_files: []
|