roo_on_rails 1.8.1 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +20 -12
- data/README.routemaster_client.md +105 -0
- data/gemfiles/rails_3.gemfile.lock +17 -5
- data/gemfiles/rails_4.gemfile.lock +17 -5
- data/gemfiles/rails_5.gemfile.lock +17 -5
- data/gemfiles/rails_5_1.gemfile.lock +17 -5
- data/lib/roo_on_rails/config.rb +8 -0
- data/lib/roo_on_rails/default.env +4 -0
- data/lib/roo_on_rails/railties/routemaster.rb +36 -0
- data/lib/roo_on_rails/routemaster/lifecycle_events.rb +56 -0
- data/lib/roo_on_rails/routemaster/publisher.rb +57 -0
- data/lib/roo_on_rails/routemaster/publishers.rb +17 -0
- data/lib/roo_on_rails/version.rb +1 -1
- data/lib/roo_on_rails.rb +1 -0
- data/roo_on_rails.gemspec +1 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82ad20e84b42ea5464aa1d089f6e54c1476f38bf
|
4
|
+
data.tar.gz: b707a2fc6d70a093fc7b75c9ab44f61d1678bdd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d94ba024d087ea2d51405d81bc9b690c072492551384d409bc0d8b34d6b24a11dd46db96e8ef5093ef6e04db731d149af91377470d0da6fc7fc328e81ec09682
|
7
|
+
data.tar.gz: 0a7839fda65b584af46860dd660a303889cb9a159502053a02ec7875e70fe1ea20c7240f12b9f0ccb2696134fe19b72d8c3b5a2b19a77d95467992feb84cab79
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -16,16 +16,18 @@
|
|
16
16
|
**Table of Contents**
|
17
17
|
|
18
18
|
- [Installation](#installation)
|
19
|
-
- [
|
20
|
-
- [
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
- [Library usage](#library-usage)
|
20
|
+
- [New Relic configuration](#new-relic-configuration)
|
21
|
+
- [Rack middleware](#rack-middleware)
|
22
|
+
- [Database configuration](#database-configuration)
|
23
|
+
- [Sidekiq](#sidekiq)
|
24
|
+
- [HireFire (for Sidekiq workers)](#hirefire-for-sidekiq-workers)
|
25
|
+
- [Logging](#logging)
|
26
|
+
- [Google OAuth authentication](#google-oauth-authentication)
|
27
|
+
- [Routemaster Client](#routemaster-client)
|
28
28
|
- [Command features](#command-features)
|
29
|
+
- [Usage](#usage)
|
30
|
+
- [Description](#description)
|
29
31
|
- [Contributing](#contributing)
|
30
32
|
- [License](#license)
|
31
33
|
|
@@ -57,9 +59,7 @@ And then execute:
|
|
57
59
|
|
58
60
|
Then re-run your test suite to make sure everything is shipshape.
|
59
61
|
|
60
|
-
##
|
61
|
-
|
62
|
-
## Configuration and usage
|
62
|
+
## Library usage
|
63
63
|
|
64
64
|
### New Relic configuration
|
65
65
|
|
@@ -199,6 +199,14 @@ application.
|
|
199
199
|
|
200
200
|
A simple but secure example is detailed in `README.google_oauth2.md`.
|
201
201
|
|
202
|
+
### Routemaster Client
|
203
|
+
|
204
|
+
When `ROUTEMASTER_ENABLED` is set to `true` we attempt to configure [`routemaster-client`](https://github.com/deliveroo/routemaster-client) on your application. In order for this to happen you need to set the following environment variables:
|
205
|
+
|
206
|
+
* `ROUTEMASTER_URL` – the full URL of your Routemaster application (mandatory)
|
207
|
+
* `ROUTEMASTER_UUID` – the UUID of your application, e.g. `logistics-dashboard` (mandatory)
|
208
|
+
|
209
|
+
If you then want to enable the publishing of events onto the event bus, you need to set `ROUTEMASTER_PUBLISHING_ENABLED` to `true` and implement publishers as needed. An example of how to do this is detailed in [`README.routemaster_client.md`](README.routemaster_client.md).
|
202
210
|
|
203
211
|
## Command features
|
204
212
|
|
@@ -0,0 +1,105 @@
|
|
1
|
+
## Using the Routemaster Client feature
|
2
|
+
|
3
|
+
[`routemaster-client`](https://github.com/deliveroo/routemaster-client) comes as a dependency of `roo_on_rails` with a basic implementation of lifecycle event publishers.
|
4
|
+
|
5
|
+
This code example assumes that you are using the latest version of the [`roo_on_rails`](roo_on_rails) gem and that you have set the correct environment variables for Routemaster Client to work on your app, as explained in the main [`README.md`](roo_on_rails#routemaster-client) file.
|
6
|
+
|
7
|
+
It also assumes that your app has an API for the resources you want to publish lifecycle events for, with matching routes and an `API_HOST` environment variable set.
|
8
|
+
|
9
|
+
### Setup lifecycle events for your models
|
10
|
+
|
11
|
+
We will most likely want to publish lifecycle events for several models, so to write slightly less code let's create a model concern first:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
# app/models/concerns/routemaster_lifecycle_events.rb
|
15
|
+
require 'roo_on_rails/routemaster/lifecycle_events'
|
16
|
+
|
17
|
+
module RoutemasterLifecycleEvents
|
18
|
+
extend ActiveSupport::Concern
|
19
|
+
include RooOnRails::Routemaster::LifecycleEvents
|
20
|
+
|
21
|
+
included do
|
22
|
+
publish_lifecycle_events
|
23
|
+
end
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
Then let's include this concern to the relevant model(s):
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# app/models/order.rb
|
31
|
+
class Order < ApplicationRecord
|
32
|
+
include RoutemasterLifecycleEvents
|
33
|
+
|
34
|
+
# ...
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
And another one for the example:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
# app/models/rider.rb
|
42
|
+
class Rider < ApplicationRecord
|
43
|
+
include RoutemasterLifecycleEvents
|
44
|
+
|
45
|
+
# ...
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
### Create publishers for lifecycle events
|
50
|
+
|
51
|
+
We have now configured our models to publish lifecycle events to Routemaster, but it won't send anything until you have enabled publishing and created matching publishers. Let's start with creating a `BasePublisher` that we can then inherit from:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
# app/publishers/base_publisher.rb
|
55
|
+
require 'roo_on_rails/routemaster/publisher'
|
56
|
+
|
57
|
+
class BasePublisher < RooOnRails::Routemaster::Publisher
|
58
|
+
include Rails.application.routes.url_helpers
|
59
|
+
|
60
|
+
# Add your method overrides here if needed
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
Then create a publisher for each model with lifecycle events enabled:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
# app/publishers/order_publisher.rb
|
68
|
+
class OrderPublisher < BasePublisher
|
69
|
+
def url
|
70
|
+
api_order_url(model, host: ENV.fetch('API_HOST'), protocol: 'https')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
and
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
# app/publishers/rider_publisher.rb
|
79
|
+
class RiderPublisher < BasePublisher
|
80
|
+
def url
|
81
|
+
api_rider_url(model, host: ENV.fetch('API_HOST'), protocol: 'https')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
### Register the publishers with Routemaster
|
87
|
+
|
88
|
+
The final step is to tell Routemaster that these publishers exist, so that it can listen to their events. We're going to do this in an initialiser:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
# config/initilizers/routemaster.rb
|
92
|
+
require 'roo_on_rails/routemaster/publishers'
|
93
|
+
|
94
|
+
PUBLISHERS = [
|
95
|
+
OrderPublisher,
|
96
|
+
RiderPublisher
|
97
|
+
].freeze
|
98
|
+
|
99
|
+
PUBLISHERS.each do |publisher|
|
100
|
+
model_class = publisher.to_s.gsub("Publisher", "").constantize
|
101
|
+
RooOnRails::Routemaster::Publishers.register(publisher, model_class: model_class)
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
We should now be all set for our app to publish lifecycle events for `orders` and `riders` onto the event bus, so that other apps can listen to them.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
roo_on_rails (1.
|
4
|
+
roo_on_rails (1.9.0)
|
5
5
|
dogstatsd-ruby
|
6
6
|
dotenv-rails (~> 2.1)
|
7
7
|
faraday
|
@@ -15,6 +15,7 @@ PATH
|
|
15
15
|
rack-ssl-enforcer
|
16
16
|
rack-timeout
|
17
17
|
rails (>= 3.2.22, < 5.2)
|
18
|
+
routemaster-client
|
18
19
|
sidekiq
|
19
20
|
|
20
21
|
GEM
|
@@ -73,10 +74,12 @@ GEM
|
|
73
74
|
dotenv (= 2.2.1)
|
74
75
|
railties (>= 3.2, < 5.2)
|
75
76
|
erubis (2.7.0)
|
76
|
-
|
77
|
+
ethon (0.10.1)
|
78
|
+
ffi (>= 1.3.0)
|
79
|
+
excon (0.58.0)
|
77
80
|
faraday (0.12.2)
|
78
81
|
multipart-post (>= 1.2, < 3)
|
79
|
-
faraday_middleware (0.
|
82
|
+
faraday_middleware (0.12.2)
|
80
83
|
faraday (>= 0.7.4, < 1.0)
|
81
84
|
ffi (1.9.18)
|
82
85
|
formatador (0.2.5)
|
@@ -134,10 +137,11 @@ GEM
|
|
134
137
|
rack (>= 1.2, < 3)
|
135
138
|
octokit (4.7.0)
|
136
139
|
sawyer (~> 0.8.0, >= 0.5.3)
|
140
|
+
oj (2.18.5)
|
137
141
|
omniauth (1.4.2)
|
138
142
|
hashie (>= 1.2, < 4)
|
139
143
|
rack (>= 1.0, < 3)
|
140
|
-
omniauth-google-oauth2 (0.5.
|
144
|
+
omniauth-google-oauth2 (0.5.2)
|
141
145
|
jwt (~> 1.5)
|
142
146
|
multi_json (~> 1.3)
|
143
147
|
omniauth (>= 1.1.1)
|
@@ -191,6 +195,11 @@ GEM
|
|
191
195
|
rdoc (3.12.2)
|
192
196
|
json (~> 1.4)
|
193
197
|
redis (3.3.3)
|
198
|
+
routemaster-client (3.1.0)
|
199
|
+
faraday (>= 0.9.0)
|
200
|
+
oj (~> 2.17)
|
201
|
+
typhoeus (~> 1.1)
|
202
|
+
wisper (~> 1.6.1)
|
194
203
|
rspec (3.6.0)
|
195
204
|
rspec-core (~> 3.6.0)
|
196
205
|
rspec-expectations (~> 3.6.0)
|
@@ -232,12 +241,15 @@ GEM
|
|
232
241
|
treetop (1.4.15)
|
233
242
|
polyglot
|
234
243
|
polyglot (>= 0.3.1)
|
244
|
+
typhoeus (1.1.2)
|
245
|
+
ethon (>= 0.9.0)
|
235
246
|
tzinfo (0.3.53)
|
236
247
|
url (0.3.2)
|
237
248
|
webmock (3.0.1)
|
238
249
|
addressable (>= 2.3.6)
|
239
250
|
crack (>= 0.3.2)
|
240
251
|
hashdiff
|
252
|
+
wisper (1.6.1)
|
241
253
|
|
242
254
|
PLATFORMS
|
243
255
|
ruby
|
@@ -263,4 +275,4 @@ DEPENDENCIES
|
|
263
275
|
webmock
|
264
276
|
|
265
277
|
BUNDLED WITH
|
266
|
-
1.
|
278
|
+
1.15.3
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
roo_on_rails (1.
|
4
|
+
roo_on_rails (1.9.0)
|
5
5
|
dogstatsd-ruby
|
6
6
|
dotenv-rails (~> 2.1)
|
7
7
|
faraday
|
@@ -15,6 +15,7 @@ PATH
|
|
15
15
|
rack-ssl-enforcer
|
16
16
|
rack-timeout
|
17
17
|
rails (>= 3.2.22, < 5.2)
|
18
|
+
routemaster-client
|
18
19
|
sidekiq
|
19
20
|
|
20
21
|
GEM
|
@@ -80,10 +81,12 @@ GEM
|
|
80
81
|
dotenv (= 2.2.1)
|
81
82
|
railties (>= 3.2, < 5.2)
|
82
83
|
erubis (2.7.0)
|
83
|
-
|
84
|
+
ethon (0.10.1)
|
85
|
+
ffi (>= 1.3.0)
|
86
|
+
excon (0.58.0)
|
84
87
|
faraday (0.12.2)
|
85
88
|
multipart-post (>= 1.2, < 3)
|
86
|
-
faraday_middleware (0.
|
89
|
+
faraday_middleware (0.12.2)
|
87
90
|
faraday (>= 0.7.4, < 1.0)
|
88
91
|
ffi (1.9.18)
|
89
92
|
formatador (0.2.5)
|
@@ -148,10 +151,11 @@ GEM
|
|
148
151
|
rack (>= 1.2, < 3)
|
149
152
|
octokit (4.7.0)
|
150
153
|
sawyer (~> 0.8.0, >= 0.5.3)
|
154
|
+
oj (2.18.5)
|
151
155
|
omniauth (1.6.1)
|
152
156
|
hashie (>= 3.4.6, < 3.6.0)
|
153
157
|
rack (>= 1.6.2, < 3)
|
154
|
-
omniauth-google-oauth2 (0.5.
|
158
|
+
omniauth-google-oauth2 (0.5.2)
|
155
159
|
jwt (~> 1.5)
|
156
160
|
multi_json (~> 1.3)
|
157
161
|
omniauth (>= 1.1.1)
|
@@ -207,6 +211,11 @@ GEM
|
|
207
211
|
rb-inotify (0.9.10)
|
208
212
|
ffi (>= 0.5.0, < 2)
|
209
213
|
redis (3.3.3)
|
214
|
+
routemaster-client (3.1.0)
|
215
|
+
faraday (>= 0.9.0)
|
216
|
+
oj (~> 2.17)
|
217
|
+
typhoeus (~> 1.1)
|
218
|
+
wisper (~> 1.6.1)
|
210
219
|
rspec (3.6.0)
|
211
220
|
rspec-core (~> 3.6.0)
|
212
221
|
rspec-expectations (~> 3.6.0)
|
@@ -247,6 +256,8 @@ GEM
|
|
247
256
|
sqlite3 (1.3.13)
|
248
257
|
thor (0.19.4)
|
249
258
|
thread_safe (0.3.6)
|
259
|
+
typhoeus (1.1.2)
|
260
|
+
ethon (>= 0.9.0)
|
250
261
|
tzinfo (1.2.3)
|
251
262
|
thread_safe (~> 0.1)
|
252
263
|
url (0.3.2)
|
@@ -254,6 +265,7 @@ GEM
|
|
254
265
|
addressable (>= 2.3.6)
|
255
266
|
crack (>= 0.3.2)
|
256
267
|
hashdiff
|
268
|
+
wisper (1.6.1)
|
257
269
|
|
258
270
|
PLATFORMS
|
259
271
|
ruby
|
@@ -278,4 +290,4 @@ DEPENDENCIES
|
|
278
290
|
webmock
|
279
291
|
|
280
292
|
BUNDLED WITH
|
281
|
-
1.
|
293
|
+
1.15.3
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
roo_on_rails (1.
|
4
|
+
roo_on_rails (1.9.0)
|
5
5
|
dogstatsd-ruby
|
6
6
|
dotenv-rails (~> 2.1)
|
7
7
|
faraday
|
@@ -15,6 +15,7 @@ PATH
|
|
15
15
|
rack-ssl-enforcer
|
16
16
|
rack-timeout
|
17
17
|
rails (>= 3.2.22, < 5.2)
|
18
|
+
routemaster-client
|
18
19
|
sidekiq
|
19
20
|
|
20
21
|
GEM
|
@@ -83,10 +84,12 @@ GEM
|
|
83
84
|
dotenv (= 2.2.1)
|
84
85
|
railties (>= 3.2, < 5.2)
|
85
86
|
erubis (2.7.0)
|
86
|
-
|
87
|
+
ethon (0.10.1)
|
88
|
+
ffi (>= 1.3.0)
|
89
|
+
excon (0.58.0)
|
87
90
|
faraday (0.12.2)
|
88
91
|
multipart-post (>= 1.2, < 3)
|
89
|
-
faraday_middleware (0.
|
92
|
+
faraday_middleware (0.12.2)
|
90
93
|
faraday (>= 0.7.4, < 1.0)
|
91
94
|
ffi (1.9.18)
|
92
95
|
formatador (0.2.5)
|
@@ -152,10 +155,11 @@ GEM
|
|
152
155
|
rack (>= 1.2, < 3)
|
153
156
|
octokit (4.7.0)
|
154
157
|
sawyer (~> 0.8.0, >= 0.5.3)
|
158
|
+
oj (2.18.5)
|
155
159
|
omniauth (1.6.1)
|
156
160
|
hashie (>= 3.4.6, < 3.6.0)
|
157
161
|
rack (>= 1.6.2, < 3)
|
158
|
-
omniauth-google-oauth2 (0.5.
|
162
|
+
omniauth-google-oauth2 (0.5.2)
|
159
163
|
jwt (~> 1.5)
|
160
164
|
multi_json (~> 1.3)
|
161
165
|
omniauth (>= 1.1.1)
|
@@ -210,6 +214,11 @@ GEM
|
|
210
214
|
rb-inotify (0.9.10)
|
211
215
|
ffi (>= 0.5.0, < 2)
|
212
216
|
redis (3.3.3)
|
217
|
+
routemaster-client (3.1.0)
|
218
|
+
faraday (>= 0.9.0)
|
219
|
+
oj (~> 2.17)
|
220
|
+
typhoeus (~> 1.1)
|
221
|
+
wisper (~> 1.6.1)
|
213
222
|
rspec (3.6.0)
|
214
223
|
rspec-core (~> 3.6.0)
|
215
224
|
rspec-expectations (~> 3.6.0)
|
@@ -250,6 +259,8 @@ GEM
|
|
250
259
|
sqlite3 (1.3.13)
|
251
260
|
thor (0.19.4)
|
252
261
|
thread_safe (0.3.6)
|
262
|
+
typhoeus (1.1.2)
|
263
|
+
ethon (>= 0.9.0)
|
253
264
|
tzinfo (1.2.3)
|
254
265
|
thread_safe (~> 0.1)
|
255
266
|
url (0.3.2)
|
@@ -260,6 +271,7 @@ GEM
|
|
260
271
|
websocket-driver (0.6.5)
|
261
272
|
websocket-extensions (>= 0.1.0)
|
262
273
|
websocket-extensions (0.1.2)
|
274
|
+
wisper (1.6.1)
|
263
275
|
|
264
276
|
PLATFORMS
|
265
277
|
ruby
|
@@ -284,4 +296,4 @@ DEPENDENCIES
|
|
284
296
|
webmock
|
285
297
|
|
286
298
|
BUNDLED WITH
|
287
|
-
1.
|
299
|
+
1.15.3
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
roo_on_rails (1.
|
4
|
+
roo_on_rails (1.9.0)
|
5
5
|
dogstatsd-ruby
|
6
6
|
dotenv-rails (~> 2.1)
|
7
7
|
faraday
|
@@ -15,6 +15,7 @@ PATH
|
|
15
15
|
rack-ssl-enforcer
|
16
16
|
rack-timeout
|
17
17
|
rails (>= 3.2.22, < 5.2)
|
18
|
+
routemaster-client
|
18
19
|
sidekiq
|
19
20
|
|
20
21
|
GEM
|
@@ -84,10 +85,12 @@ GEM
|
|
84
85
|
railties (>= 3.2, < 5.2)
|
85
86
|
erubi (1.6.0)
|
86
87
|
erubis (2.7.0)
|
87
|
-
|
88
|
+
ethon (0.10.1)
|
89
|
+
ffi (>= 1.3.0)
|
90
|
+
excon (0.58.0)
|
88
91
|
faraday (0.12.2)
|
89
92
|
multipart-post (>= 1.2, < 3)
|
90
|
-
faraday_middleware (0.
|
93
|
+
faraday_middleware (0.12.2)
|
91
94
|
faraday (>= 0.7.4, < 1.0)
|
92
95
|
ffi (1.9.18)
|
93
96
|
formatador (0.2.5)
|
@@ -153,10 +156,11 @@ GEM
|
|
153
156
|
rack (>= 1.2, < 3)
|
154
157
|
octokit (4.7.0)
|
155
158
|
sawyer (~> 0.8.0, >= 0.5.3)
|
159
|
+
oj (2.18.5)
|
156
160
|
omniauth (1.6.1)
|
157
161
|
hashie (>= 3.4.6, < 3.6.0)
|
158
162
|
rack (>= 1.6.2, < 3)
|
159
|
-
omniauth-google-oauth2 (0.5.
|
163
|
+
omniauth-google-oauth2 (0.5.2)
|
160
164
|
jwt (~> 1.5)
|
161
165
|
multi_json (~> 1.3)
|
162
166
|
omniauth (>= 1.1.1)
|
@@ -211,6 +215,11 @@ GEM
|
|
211
215
|
rb-inotify (0.9.10)
|
212
216
|
ffi (>= 0.5.0, < 2)
|
213
217
|
redis (3.3.3)
|
218
|
+
routemaster-client (3.1.0)
|
219
|
+
faraday (>= 0.9.0)
|
220
|
+
oj (~> 2.17)
|
221
|
+
typhoeus (~> 1.1)
|
222
|
+
wisper (~> 1.6.1)
|
214
223
|
rspec (3.6.0)
|
215
224
|
rspec-core (~> 3.6.0)
|
216
225
|
rspec-expectations (~> 3.6.0)
|
@@ -251,6 +260,8 @@ GEM
|
|
251
260
|
sqlite3 (1.3.13)
|
252
261
|
thor (0.19.4)
|
253
262
|
thread_safe (0.3.6)
|
263
|
+
typhoeus (1.1.2)
|
264
|
+
ethon (>= 0.9.0)
|
254
265
|
tzinfo (1.2.3)
|
255
266
|
thread_safe (~> 0.1)
|
256
267
|
url (0.3.2)
|
@@ -261,6 +272,7 @@ GEM
|
|
261
272
|
websocket-driver (0.6.5)
|
262
273
|
websocket-extensions (>= 0.1.0)
|
263
274
|
websocket-extensions (0.1.2)
|
275
|
+
wisper (1.6.1)
|
264
276
|
|
265
277
|
PLATFORMS
|
266
278
|
ruby
|
@@ -285,4 +297,4 @@ DEPENDENCIES
|
|
285
297
|
webmock
|
286
298
|
|
287
299
|
BUNDLED WITH
|
288
|
-
1.
|
300
|
+
1.15.3
|
data/lib/roo_on_rails/config.rb
CHANGED
@@ -25,6 +25,14 @@ module RooOnRails
|
|
25
25
|
ENV.fetch('GOOGLE_AUTH_CONTROLLER')
|
26
26
|
end
|
27
27
|
|
28
|
+
def routemaster_enabled?
|
29
|
+
enabled? 'ROUTEMASTER_ENABLED', default: false
|
30
|
+
end
|
31
|
+
|
32
|
+
def routemaster_publishing_enabled?
|
33
|
+
enabled? 'ROUTEMASTER_PUBLISHING_ENABLED', default: false
|
34
|
+
end
|
35
|
+
|
28
36
|
private
|
29
37
|
|
30
38
|
ENABLED_PATTERN = /\A(YES|TRUE|ON|1)\Z/i
|
@@ -15,6 +15,10 @@ NEW_RELIC_DEVELOPER_MODE=false
|
|
15
15
|
NEW_RELIC_LICENSE_KEY=override-me
|
16
16
|
RACK_SERVICE_TIMEOUT=10
|
17
17
|
RACK_WAIT_TIMEOUT=30
|
18
|
+
ROUTEMASTER_URL=''
|
19
|
+
ROUTEMASTER_UUID=''
|
20
|
+
ROUTEMASTER_ENABLED=false
|
21
|
+
ROUTEMASTER_PUBLISHING_ENABLED=false
|
18
22
|
SIDEKIQ_ENABLED=true
|
19
23
|
SIDEKIQ_THREADS=25
|
20
24
|
SIDEKIQ_DATABASE_REAPING_FREQUENCY=10
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'roo_on_rails/config'
|
2
|
+
|
3
|
+
module RooOnRails
|
4
|
+
module Railties
|
5
|
+
class Routemaster < Rails::Railtie
|
6
|
+
initializer 'roo_on_rails.routemaster' do
|
7
|
+
next unless Config.routemaster_enabled?
|
8
|
+
|
9
|
+
$stderr.puts 'initializer roo_on_rails.routemaster'
|
10
|
+
|
11
|
+
abort 'Aborting: ROUTEMASTER_URL and ROUTEMASTER_UUID are required' if bus_details_missing?
|
12
|
+
|
13
|
+
require 'routemaster/client'
|
14
|
+
|
15
|
+
::Routemaster::Client.configure do |config|
|
16
|
+
config.url = routemaster_url
|
17
|
+
config.uuid = routemaster_uuid
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def bus_details_missing?
|
24
|
+
routemaster_url.blank? || routemaster_uuid.blank?
|
25
|
+
end
|
26
|
+
|
27
|
+
def routemaster_url
|
28
|
+
ENV.fetch('ROUTEMASTER_URL')
|
29
|
+
end
|
30
|
+
|
31
|
+
def routemaster_uuid
|
32
|
+
ENV.fetch('ROUTEMASTER_UUID')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'new_relic/agent'
|
3
|
+
require 'roo_on_rails/routemaster/publishers'
|
4
|
+
|
5
|
+
module RooOnRails
|
6
|
+
module Routemaster
|
7
|
+
module LifecycleEvents
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
ACTIVE_RECORD_TO_ROUTEMASTER_EVENT_MAP = {
|
11
|
+
create: :created,
|
12
|
+
update: :updated,
|
13
|
+
destroy: :deleted,
|
14
|
+
noop: :noop
|
15
|
+
}.freeze
|
16
|
+
private_constant :ACTIVE_RECORD_TO_ROUTEMASTER_EVENT_MAP
|
17
|
+
|
18
|
+
def publish_lifecycle_event(event)
|
19
|
+
publishers = Routemaster::Publishers.for(self, routemaster_event_type(event))
|
20
|
+
publishers.each do |publisher|
|
21
|
+
begin
|
22
|
+
publisher.publish!
|
23
|
+
rescue => e
|
24
|
+
NewRelic::Agent.notice_error(e)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def routemaster_event_type(event)
|
32
|
+
ACTIVE_RECORD_TO_ROUTEMASTER_EVENT_MAP[event].tap do |type|
|
33
|
+
raise "invalid lifecycle event '#{event}'" unless type
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
%i(create update destroy noop).each do |event|
|
38
|
+
define_method("publish_lifecycle_event_on_#{event}") do
|
39
|
+
publish_lifecycle_event(event)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module ClassMethods
|
44
|
+
def publish_lifecycle_events(*events)
|
45
|
+
events = events.any? ? events : %i(create update destroy)
|
46
|
+
events.each do |event|
|
47
|
+
after_commit(
|
48
|
+
:"publish_lifecycle_event_on_#{event}",
|
49
|
+
on: event
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'roo_on_rails/config'
|
2
|
+
require 'routemaster/client'
|
3
|
+
|
4
|
+
module RooOnRails
|
5
|
+
module Routemaster
|
6
|
+
class Publisher
|
7
|
+
attr_reader :model, :event
|
8
|
+
|
9
|
+
def initialize(model, event, client: ::Routemaster::Client)
|
10
|
+
@model = model
|
11
|
+
@event = event
|
12
|
+
@client = client
|
13
|
+
end
|
14
|
+
|
15
|
+
def publish?
|
16
|
+
noop? || @model.new_record? || @model.previous_changes.any?
|
17
|
+
end
|
18
|
+
|
19
|
+
def will_publish?
|
20
|
+
Config.routemaster_publishing_enabled? && publish?
|
21
|
+
end
|
22
|
+
|
23
|
+
def publish!
|
24
|
+
return unless will_publish?
|
25
|
+
@client.send(@event, topic, url, data: stringify_keys(data))
|
26
|
+
end
|
27
|
+
|
28
|
+
def topic
|
29
|
+
@model.class.name.tableize
|
30
|
+
end
|
31
|
+
|
32
|
+
def url
|
33
|
+
raise NotImplementedError
|
34
|
+
end
|
35
|
+
|
36
|
+
def data
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
%i(created updated deleted noop).each do |event_type|
|
41
|
+
define_method :"#{event_type}?" do
|
42
|
+
@event.to_sym == event_type
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def stringify_keys(hash)
|
49
|
+
return hash if hash.nil? || hash.empty?
|
50
|
+
|
51
|
+
hash.each_with_object({}) do |(k, v), h|
|
52
|
+
h[k.to_s] = v.is_a?(Hash) ? stringify_keys(v) : v
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RooOnRails
|
2
|
+
module Routemaster
|
3
|
+
module Publishers
|
4
|
+
@publishers = {}
|
5
|
+
|
6
|
+
def self.register(publisher_class, model_class:)
|
7
|
+
@publishers[model_class] ||= Set.new
|
8
|
+
@publishers[model_class] << publisher_class
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.for(model, event)
|
12
|
+
publisher_classes = @publishers[model.class]
|
13
|
+
publisher_classes.map { |c| c.new(model, event) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/roo_on_rails/version.rb
CHANGED
data/lib/roo_on_rails.rb
CHANGED
data/roo_on_rails.gemspec
CHANGED
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_runtime_dependency 'omniauth-google-oauth2'
|
36
36
|
spec.add_runtime_dependency 'faraday'
|
37
37
|
spec.add_runtime_dependency 'faraday_middleware'
|
38
|
+
spec.add_runtime_dependency 'routemaster-client'
|
38
39
|
|
39
40
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
40
41
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roo_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien Letessier
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv-rails
|
@@ -212,6 +212,20 @@ dependencies:
|
|
212
212
|
- - ">="
|
213
213
|
- !ruby/object:Gem::Version
|
214
214
|
version: '0'
|
215
|
+
- !ruby/object:Gem::Dependency
|
216
|
+
name: routemaster-client
|
217
|
+
requirement: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
222
|
+
type: :runtime
|
223
|
+
prerelease: false
|
224
|
+
version_requirements: !ruby/object:Gem::Requirement
|
225
|
+
requirements:
|
226
|
+
- - ">="
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '0'
|
215
229
|
- !ruby/object:Gem::Dependency
|
216
230
|
name: bundler
|
217
231
|
requirement: !ruby/object:Gem::Requirement
|
@@ -360,6 +374,7 @@ files:
|
|
360
374
|
- LICENSE.txt
|
361
375
|
- README.google_oauth2.md
|
362
376
|
- README.md
|
377
|
+
- README.routemaster_client.md
|
363
378
|
- Rakefile
|
364
379
|
- appraise
|
365
380
|
- bin/console
|
@@ -415,7 +430,11 @@ files:
|
|
415
430
|
- lib/roo_on_rails/railties/http.rb
|
416
431
|
- lib/roo_on_rails/railties/new_relic.rb
|
417
432
|
- lib/roo_on_rails/railties/rake_tasks.rb
|
433
|
+
- lib/roo_on_rails/railties/routemaster.rb
|
418
434
|
- lib/roo_on_rails/railties/sidekiq.rb
|
435
|
+
- lib/roo_on_rails/routemaster/lifecycle_events.rb
|
436
|
+
- lib/roo_on_rails/routemaster/publisher.rb
|
437
|
+
- lib/roo_on_rails/routemaster/publishers.rb
|
419
438
|
- lib/roo_on_rails/shell.rb
|
420
439
|
- lib/roo_on_rails/sidekiq/loader.rb
|
421
440
|
- lib/roo_on_rails/sidekiq/metrics_worker.rb
|