tpt-rails 1.6.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -3
- data/app/models/tpt/rails/application_event.rb +1 -1
- data/app/models/tpt/rails/event_bridge_publisher.rb +7 -7
- data/lib/tpt/rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0395183e764d77487d191133045533748b1120aa919bd2904d19e923c58b5c1d'
|
4
|
+
data.tar.gz: f8591848d97fb4324aed4318183198db27ccfcff116ad43f806cd2322aadcb57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3093e622d8895edf09b3d2ee025c1356e89bdd6d7ea95dd623e5f870e8d2adab915bc4f279c548f24d0636ee902825c163b1ea61f7ce21ef5a66c970dc0c55f8
|
7
|
+
data.tar.gz: 11459ad795f7603c051f7c509ff475bdfd21bd52ce37b26ad4792da3a833fdea0a4294f614965cd28a0716f51ed79039b5fe39ebde21458e2901595e6f0ca1e7
|
data/README.md
CHANGED
@@ -68,7 +68,13 @@ See the documentation in [lib/tpt/rails.rb](lib/tpt/rails.rb).
|
|
68
68
|
|
69
69
|
`Tpt::Rails::EventBridgePublisher` is the class used to emit events to EventBridge (in batches). To use:
|
70
70
|
|
71
|
-
1.
|
71
|
+
1. Add EventBridge to your gemfile:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
gem "aws-sdk-eventbridge", "~> 1.3.0"
|
75
|
+
```
|
76
|
+
|
77
|
+
2. In an initializer, pass in the `Datadog::Statsd` object you're using to the class method ::set_metrics.
|
72
78
|
(Failure to do so will result in an error.) When testing, you can pass in a local Statsd, eg:
|
73
79
|
|
74
80
|
```ruby
|
@@ -77,13 +83,13 @@ See the documentation in [lib/tpt/rails.rb](lib/tpt/rails.rb).
|
|
77
83
|
)
|
78
84
|
```
|
79
85
|
|
80
|
-
|
86
|
+
3. By default (#new with no arguments) EventBridgePublisher will try to use the following environment
|
81
87
|
variables: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `TPT_EVENT_SOURCE`, `TPT_SHARED_EVENT_BUS_NAME`.
|
82
88
|
|
83
89
|
Additional configuration can be set as part of the constructor;
|
84
90
|
[see event_bridge_publisher.rb implementation](https://github.com/TeachersPayTeachers/tpt-rails/blob/ad768d3bac0c8bd28e60a48a89aed36f01c4e17b/app/models/tpt/rails/event_bridge_publisher.rb) for more details.
|
85
91
|
|
86
|
-
|
92
|
+
4. Create events by instantiating or inheriting from `Tpt::Rails::ApplicationEvent`. Event types are derived from the text before
|
87
93
|
"Event", so ResourceEvent has the event_type "Resource". Pass in an event or an array of events to EventBridgePublisher#publish
|
88
94
|
and they will be published immediately. Large arrays will be batched (default 10 per batch).
|
89
95
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Tpt::Rails
|
2
2
|
class EventBridgePublisher
|
3
|
+
attr_accessor :batch_size
|
4
|
+
|
3
5
|
def initialize(
|
4
6
|
event_bus_name: default_event_bus_name,
|
5
7
|
event_source: default_event_source,
|
@@ -26,7 +28,9 @@ module Tpt::Rails
|
|
26
28
|
events
|
27
29
|
end
|
28
30
|
|
29
|
-
|
31
|
+
private
|
32
|
+
attr_reader :client, :event_bus_name, :event_source
|
33
|
+
|
30
34
|
def publish_batch(events)
|
31
35
|
metrics.time('tpt.event_bridge.publish_batch') do
|
32
36
|
wrapped_events = wrap_events(events)
|
@@ -77,14 +81,10 @@ module Tpt::Rails
|
|
77
81
|
res.data.entries
|
78
82
|
end
|
79
83
|
|
80
|
-
private
|
81
|
-
|
82
|
-
attr_reader :client, :event_bus_name, :event_source
|
83
|
-
|
84
84
|
def make_client(options)
|
85
85
|
all_options = {
|
86
|
-
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
|
87
|
-
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
|
86
|
+
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID', nil),
|
87
|
+
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY', nil),
|
88
88
|
region: ENV.fetch('AWS_REGION', 'us-east-1'),
|
89
89
|
http_open_timeout: 1, # default is 15
|
90
90
|
http_read_timeout: 1, # default is 60
|
data/lib/tpt/rails/version.rb
CHANGED