rabbitek 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +2 -3
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +108 -8
- data/README.md +1 -0
- data/Rakefile +7 -0
- data/lib/rabbitek.rb +12 -2
- data/lib/rabbitek/cli.rb +8 -3
- data/lib/rabbitek/config.rb +7 -5
- data/lib/rabbitek/loggable.rb +1 -0
- data/lib/rabbitek/rails.rb +43 -0
- data/lib/rabbitek/server/hooks/active_record_connection_reset.rb +32 -0
- data/lib/rabbitek/server/starter.rb +1 -1
- data/lib/rabbitek/version.rb +1 -1
- data/rabbitek.gemspec +3 -1
- metadata +35 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 61812d7a27d392ac1fd654f0a181972b716be920d0e8d0579537f685d1d16d42
|
4
|
+
data.tar.gz: 800b02c54302fcd9c380ebb3effb63e38f28f85f4bfeb6e4731eb11385a92bbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 736fd9459b74ab310078f10be4835b600acdec3c8e04093c6d5fa5c90a364a5f1de0f17f6ae4de56cdea56237e63fd0012773732b3a6501970aa55539d826727
|
7
|
+
data.tar.gz: 6c5d6d0a9b429cc88b0c844c78c3de40e0aacad2d98464c4897cfbecbba2b6b745d4823e2739b2fc995953c9273a32b1434052b0ce63d8929cbe4d767448d1b3
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## v0.3.0
|
2
|
+
|
3
|
+
Improvements:
|
4
|
+
* Handle AR connections correctly (hook in Rails < 5, reloader implementation in Rails >= 5)
|
5
|
+
* Allow to specify Rails app folder to require
|
6
|
+
|
7
|
+
New features:
|
8
|
+
* Add sentry integration
|
9
|
+
|
1
10
|
## v0.2.0
|
2
11
|
|
3
12
|
### Breaking changes
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rabbitek (0.
|
4
|
+
rabbitek (0.3.0)
|
5
5
|
activesupport (> 3.0)
|
6
6
|
bunny (~> 2.11.0)
|
7
7
|
oj (~> 3.6)
|
@@ -11,27 +11,114 @@ PATH
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
+
actioncable (5.2.2)
|
15
|
+
actionpack (= 5.2.2)
|
16
|
+
nio4r (~> 2.0)
|
17
|
+
websocket-driver (>= 0.6.1)
|
18
|
+
actionmailer (5.2.2)
|
19
|
+
actionpack (= 5.2.2)
|
20
|
+
actionview (= 5.2.2)
|
21
|
+
activejob (= 5.2.2)
|
22
|
+
mail (~> 2.5, >= 2.5.4)
|
23
|
+
rails-dom-testing (~> 2.0)
|
24
|
+
actionpack (5.2.2)
|
25
|
+
actionview (= 5.2.2)
|
26
|
+
activesupport (= 5.2.2)
|
27
|
+
rack (~> 2.0)
|
28
|
+
rack-test (>= 0.6.3)
|
29
|
+
rails-dom-testing (~> 2.0)
|
30
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
31
|
+
actionview (5.2.2)
|
32
|
+
activesupport (= 5.2.2)
|
33
|
+
builder (~> 3.1)
|
34
|
+
erubi (~> 1.4)
|
35
|
+
rails-dom-testing (~> 2.0)
|
36
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
37
|
+
activejob (5.2.2)
|
38
|
+
activesupport (= 5.2.2)
|
39
|
+
globalid (>= 0.3.6)
|
40
|
+
activemodel (5.2.2)
|
41
|
+
activesupport (= 5.2.2)
|
42
|
+
activerecord (5.2.2)
|
43
|
+
activemodel (= 5.2.2)
|
44
|
+
activesupport (= 5.2.2)
|
45
|
+
arel (>= 9.0)
|
46
|
+
activestorage (5.2.2)
|
47
|
+
actionpack (= 5.2.2)
|
48
|
+
activerecord (= 5.2.2)
|
49
|
+
marcel (~> 0.3.1)
|
14
50
|
activesupport (5.2.2)
|
15
51
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
52
|
i18n (>= 0.7, < 2)
|
17
53
|
minitest (~> 5.1)
|
18
54
|
tzinfo (~> 1.1)
|
19
55
|
amq-protocol (2.3.0)
|
56
|
+
arel (9.0.0)
|
20
57
|
ast (2.4.0)
|
58
|
+
builder (3.2.3)
|
21
59
|
bunny (2.11.0)
|
22
60
|
amq-protocol (~> 2.3.0)
|
23
|
-
|
61
|
+
coderay (1.1.2)
|
62
|
+
concurrent-ruby (1.1.4)
|
63
|
+
crass (1.0.4)
|
24
64
|
diff-lcs (1.3)
|
25
|
-
|
65
|
+
erubi (1.8.0)
|
66
|
+
globalid (0.4.2)
|
67
|
+
activesupport (>= 4.2.0)
|
68
|
+
i18n (1.5.2)
|
26
69
|
concurrent-ruby (~> 1.0)
|
27
70
|
jaro_winkler (1.5.1)
|
71
|
+
loofah (2.2.3)
|
72
|
+
crass (~> 1.0.2)
|
73
|
+
nokogiri (>= 1.5.9)
|
74
|
+
mail (2.7.1)
|
75
|
+
mini_mime (>= 0.1.1)
|
76
|
+
marcel (0.3.3)
|
77
|
+
mimemagic (~> 0.3.2)
|
78
|
+
method_source (0.9.2)
|
79
|
+
mimemagic (0.3.3)
|
80
|
+
mini_mime (1.0.2)
|
81
|
+
mini_portile2 (2.4.0)
|
28
82
|
minitest (5.11.3)
|
29
|
-
|
30
|
-
|
83
|
+
nio4r (2.4.0)
|
84
|
+
nokogiri (1.10.3)
|
85
|
+
mini_portile2 (~> 2.4.0)
|
86
|
+
oj (3.8.1)
|
87
|
+
opentracing (0.5.0)
|
31
88
|
parallel (1.12.1)
|
32
89
|
parser (2.5.1.2)
|
33
90
|
ast (~> 2.4.0)
|
34
91
|
powerpack (0.1.2)
|
92
|
+
pry (0.12.2)
|
93
|
+
coderay (~> 1.1.0)
|
94
|
+
method_source (~> 0.9.0)
|
95
|
+
rack (2.0.7)
|
96
|
+
rack-test (1.1.0)
|
97
|
+
rack (>= 1.0, < 3)
|
98
|
+
rails (5.2.2)
|
99
|
+
actioncable (= 5.2.2)
|
100
|
+
actionmailer (= 5.2.2)
|
101
|
+
actionpack (= 5.2.2)
|
102
|
+
actionview (= 5.2.2)
|
103
|
+
activejob (= 5.2.2)
|
104
|
+
activemodel (= 5.2.2)
|
105
|
+
activerecord (= 5.2.2)
|
106
|
+
activestorage (= 5.2.2)
|
107
|
+
activesupport (= 5.2.2)
|
108
|
+
bundler (>= 1.3.0)
|
109
|
+
railties (= 5.2.2)
|
110
|
+
sprockets-rails (>= 2.0.0)
|
111
|
+
rails-dom-testing (2.0.3)
|
112
|
+
activesupport (>= 4.2.0)
|
113
|
+
nokogiri (>= 1.6)
|
114
|
+
rails-html-sanitizer (1.0.4)
|
115
|
+
loofah (~> 2.2, >= 2.2.2)
|
116
|
+
railties (5.2.2)
|
117
|
+
actionpack (= 5.2.2)
|
118
|
+
activesupport (= 5.2.2)
|
119
|
+
method_source
|
120
|
+
rake (>= 0.8.7)
|
121
|
+
thor (>= 0.19.0, < 2.0)
|
35
122
|
rainbow (3.0.0)
|
36
123
|
rake (10.5.0)
|
37
124
|
rspec (3.7.0)
|
@@ -56,21 +143,34 @@ GEM
|
|
56
143
|
ruby-progressbar (~> 1.7)
|
57
144
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
58
145
|
ruby-progressbar (1.10.0)
|
59
|
-
slop (4.
|
146
|
+
slop (4.7.0)
|
147
|
+
sprockets (3.7.2)
|
148
|
+
concurrent-ruby (~> 1.0)
|
149
|
+
rack (> 1, < 3)
|
150
|
+
sprockets-rails (3.2.1)
|
151
|
+
actionpack (>= 4.0)
|
152
|
+
activesupport (>= 4.0)
|
153
|
+
sprockets (>= 3.0.0)
|
154
|
+
thor (0.20.3)
|
60
155
|
thread_safe (0.3.6)
|
61
156
|
tzinfo (1.2.5)
|
62
157
|
thread_safe (~> 0.1)
|
63
158
|
unicode-display_width (1.4.0)
|
159
|
+
websocket-driver (0.7.1)
|
160
|
+
websocket-extensions (>= 0.1.0)
|
161
|
+
websocket-extensions (0.1.4)
|
64
162
|
|
65
163
|
PLATFORMS
|
66
164
|
ruby
|
67
165
|
|
68
166
|
DEPENDENCIES
|
69
|
-
bundler (~>
|
167
|
+
bundler (~> 2.0)
|
168
|
+
pry
|
70
169
|
rabbitek!
|
170
|
+
rails (~> 5)
|
71
171
|
rake (~> 10.0)
|
72
172
|
rspec (~> 3.0)
|
73
173
|
rubocop (~> 0.58.0)
|
74
174
|
|
75
175
|
BUNDLED WITH
|
76
|
-
|
176
|
+
2.0.1
|
data/README.md
CHANGED
@@ -10,6 +10,7 @@ High performance, easy to use background job processing library for Ruby using R
|
|
10
10
|
* Client & Server hooks
|
11
11
|
* OpenTracing (http://opentracing.io/) instrumentation
|
12
12
|
* NewRelic instrumentation for sending errors
|
13
|
+
* Sentry instrumentation for sending errors
|
13
14
|
|
14
15
|
## Installation
|
15
16
|
|
data/Rakefile
CHANGED
data/lib/rabbitek.rb
CHANGED
@@ -14,8 +14,14 @@ require 'active_support/core_ext/string/inflections'
|
|
14
14
|
|
15
15
|
current_dir = File.dirname(__FILE__)
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
require 'rabbitek/bunny_connection'
|
18
|
+
require 'rabbitek/cli'
|
19
|
+
require 'rabbitek/config'
|
20
|
+
require 'rabbitek/loggable'
|
21
|
+
Dir.glob("#{current_dir}/rabbitek/cli/**/*.rb").each { |file| require file }
|
22
|
+
Dir.glob("#{current_dir}/rabbitek/client/**/*.rb").each { |file| require file }
|
23
|
+
Dir.glob("#{current_dir}/rabbitek/server/**/*.rb").each { |file| require file }
|
24
|
+
Dir.glob("#{current_dir}/rabbitek/utils/**/*.rb").each { |file| require file }
|
19
25
|
|
20
26
|
##
|
21
27
|
# High performance background job processing using RabbitMQ
|
@@ -28,6 +34,10 @@ module Rabbitek
|
|
28
34
|
yield(config)
|
29
35
|
end
|
30
36
|
|
37
|
+
def self.reloader
|
38
|
+
config.reloader
|
39
|
+
end
|
40
|
+
|
31
41
|
def self.logger
|
32
42
|
@config.logger
|
33
43
|
end
|
data/lib/rabbitek/cli.rb
CHANGED
@@ -46,8 +46,8 @@ module Rabbitek
|
|
46
46
|
def opts
|
47
47
|
@opts ||= Slop.parse do |o|
|
48
48
|
o.string '-c', '--config', 'config file path. Default: "config/rabbitek.yaml"', default: 'config/rabbitek.yml'
|
49
|
-
o.string '-r', '--require', 'file to require while booting. Default: "
|
50
|
-
default: '
|
49
|
+
o.string '-r', '--require', 'rails app location or file to require while booting. Default: "."',
|
50
|
+
default: '.'
|
51
51
|
o.on '--version', 'print the version' do
|
52
52
|
puts VERSION
|
53
53
|
exit
|
@@ -64,7 +64,12 @@ module Rabbitek
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def require_application
|
67
|
-
require File.expand_path(opts[:require])
|
67
|
+
require File.expand_path(opts[:require]) unless File.directory?(opts[:require])
|
68
|
+
|
69
|
+
# Rails application provided
|
70
|
+
require 'rails'
|
71
|
+
require 'rabbitek/rails'
|
72
|
+
require File.expand_path("#{opts[:require]}/config/environment.rb")
|
68
73
|
end
|
69
74
|
|
70
75
|
def map_consumer_workers!
|
data/lib/rabbitek/config.rb
CHANGED
@@ -8,7 +8,9 @@ module Rabbitek
|
|
8
8
|
bunny_configuration: { hosts: 'localhost:5672', vhost: '/' },
|
9
9
|
log_format: 'json',
|
10
10
|
enable_newrelic: true,
|
11
|
-
|
11
|
+
enable_sentry: true,
|
12
|
+
logger: Logger.new(STDOUT),
|
13
|
+
reloader: proc { |&block| block.call }
|
12
14
|
}.freeze
|
13
15
|
|
14
16
|
attr_accessor(*DEFAULTS.keys)
|
@@ -20,12 +22,12 @@ module Rabbitek
|
|
20
22
|
@server_hooks_config = []
|
21
23
|
end
|
22
24
|
|
23
|
-
def add_client_hook(hook_object)
|
24
|
-
@client_hooks_config
|
25
|
+
def add_client_hook(hook_object, position = @client_hooks_config.size)
|
26
|
+
@client_hooks_config.insert(position, hook_object)
|
25
27
|
end
|
26
28
|
|
27
|
-
def add_server_hook(hook_object)
|
28
|
-
@server_hooks_config
|
29
|
+
def add_server_hook(hook_object, position = @server_hooks_config.size)
|
30
|
+
@server_hooks_config.insert(position, hook_object)
|
29
31
|
end
|
30
32
|
|
31
33
|
def client_hooks
|
data/lib/rabbitek/loggable.rb
CHANGED
@@ -15,6 +15,7 @@ module Rabbitek
|
|
15
15
|
def error(msg)
|
16
16
|
log_msg(:error, msg)
|
17
17
|
NewRelic::Agent.notice_error(msg) if Rabbitek.config.enable_newrelic && Object.const_defined?('NewRelic')
|
18
|
+
Raven.capture_exception(msg) if Rabbitek.config.enable_sentry && Object.const_defined?('Raven')
|
18
19
|
true
|
19
20
|
end
|
20
21
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rabbitek
|
4
|
+
##
|
5
|
+
# Rails extensions
|
6
|
+
class Rails < ::Rails::Engine
|
7
|
+
include Loggable
|
8
|
+
|
9
|
+
config.before_configuration do
|
10
|
+
if ::Rails::VERSION::MAJOR < 5 && defined?(::ActiveRecord)
|
11
|
+
info 'Adding Rabbitek::Server::Hooks::ActiveRecordConnectionReset hook'
|
12
|
+
|
13
|
+
Rabbitek.configure do |c|
|
14
|
+
c.add_server_hook(Rabbitek::Server::Hooks::ActiveRecordConnectionReset.new, 0)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
config.after_initialize do
|
20
|
+
if ::Rails::VERSION::MAJOR >= 5
|
21
|
+
info 'Using Rails code reloader'
|
22
|
+
|
23
|
+
Rabbitek.configure { |c| c.reloader = RailsReloader.new }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Implementation of reloader for Rails
|
29
|
+
class RailsReloader
|
30
|
+
def initialize
|
31
|
+
@app = ::Rails.application
|
32
|
+
end
|
33
|
+
|
34
|
+
def call
|
35
|
+
@app.reloader.wrap { yield }
|
36
|
+
end
|
37
|
+
|
38
|
+
def inspect
|
39
|
+
"#<Rabbitek::Rails::RailsReloader @app=#{@app.class.name}>"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../server_hook'
|
4
|
+
|
5
|
+
module Rabbitek
|
6
|
+
module Server
|
7
|
+
module Hooks
|
8
|
+
##
|
9
|
+
# Active record connection reset to maintain correct connection state
|
10
|
+
# Used only in Rails < 5
|
11
|
+
class ActiveRecordConnectionReset < Rabbitek::ServerHook
|
12
|
+
def initialize
|
13
|
+
raise ArgumentError, 'Use AR connection reset only in Rails < 5!' unless should_allow_hook?
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(consumer, message)
|
17
|
+
::ActiveRecord::Base.establish_connection unless ::ActiveRecord::Base.connection.active?
|
18
|
+
|
19
|
+
super
|
20
|
+
ensure
|
21
|
+
::ActiveRecord::Base.clear_active_connections!
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def should_allow_hook?
|
27
|
+
defined?(::Rails) && ::Rails::VERSION::MAJOR < 5
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -18,7 +18,7 @@ module Rabbitek
|
|
18
18
|
|
19
19
|
work_queue.subscribe(manual_ack: true) do |delivery_info, properties, payload|
|
20
20
|
message = Message.new(delivery_info: delivery_info, properties: properties, payload: payload)
|
21
|
-
on_message_received(message)
|
21
|
+
Rabbitek.reloader.call { on_message_received(message) }
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
data/lib/rabbitek/version.rb
CHANGED
data/rabbitek.gemspec
CHANGED
@@ -29,7 +29,9 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_dependency 'opentracing', '~> 0.4'
|
30
30
|
spec.add_dependency 'slop', '~> 4.0'
|
31
31
|
|
32
|
-
spec.add_development_dependency 'bundler', '~>
|
32
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
33
|
+
spec.add_development_dependency 'pry'
|
34
|
+
spec.add_development_dependency 'rails', '~> 5'
|
33
35
|
spec.add_development_dependency 'rake', '~> 10.0'
|
34
36
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
35
37
|
spec.add_development_dependency 'rubocop', '~> 0.58.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbitek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boostcom
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -86,14 +86,42 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '2.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '2.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '5'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '5'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
126
|
name: rake
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,8 +196,10 @@ files:
|
|
168
196
|
- lib/rabbitek/client/publisher.rb
|
169
197
|
- lib/rabbitek/config.rb
|
170
198
|
- lib/rabbitek/loggable.rb
|
199
|
+
- lib/rabbitek/rails.rb
|
171
200
|
- lib/rabbitek/server/batcher.rb
|
172
201
|
- lib/rabbitek/server/consumer.rb
|
202
|
+
- lib/rabbitek/server/hooks/active_record_connection_reset.rb
|
173
203
|
- lib/rabbitek/server/hooks/opentracing.rb
|
174
204
|
- lib/rabbitek/server/hooks/retry.rb
|
175
205
|
- lib/rabbitek/server/hooks/time_tracker.rb
|
@@ -202,8 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
232
|
- !ruby/object:Gem::Version
|
203
233
|
version: '0'
|
204
234
|
requirements: []
|
205
|
-
|
206
|
-
rubygems_version: 2.5.1
|
235
|
+
rubygems_version: 3.0.3
|
207
236
|
signing_key:
|
208
237
|
specification_version: 4
|
209
238
|
summary: High performance background job processing
|