staged_event 0.0.1 → 0.0.2
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9857444ea3c1fe90c3384ebb2c0885b1238c318ee004ea15bbc8416e2956ee2
|
4
|
+
data.tar.gz: 130bb8f5daea2d867ab302878c90b9b1051666728ac61df082c39f4fb8337be1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67da3f9926591dc20af3a5b4afd6023715246109fc6e2956831503308f6b325c1ccdf36da903917e994676ee584762e2f2068701937a5daa45296f016521504b
|
7
|
+
data.tar.gz: c87ec0b8de498e1e4d355ebef73bef1b5855dc3d435bb79ff187230d729484f6eb6406ed511ed821207cdc12f8a4fd5461acf575e30b939b09e0f885ee9fdec6
|
data/README.md
CHANGED
@@ -36,6 +36,24 @@ rails db:migrate
|
|
36
36
|
|
37
37
|
### Publishing Events
|
38
38
|
|
39
|
+
A typical usage of StagedEvent would look something like this:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
ActiveRecord::Base.transaction do
|
43
|
+
user = User.create!(params)
|
44
|
+
|
45
|
+
StagedEvent.save_proto!(MyEvents::UserCreatedEvent.new(name: user.name, email: user.email))
|
46
|
+
end
|
47
|
+
```
|
48
|
+
This guarantees that a) creating a new User, and b) publishing the associated event, both happen atomically even though b) will result in sending data to an external system.
|
49
|
+
|
50
|
+
An alternate syntax if you need access to the ActiveRecord model for the event is:
|
51
|
+
```ruby
|
52
|
+
event = StagedEvent.from_proto(MyEvents::UserCreatedEvent.new(name: user.name, email: user.email))
|
53
|
+
event.is_a?(ActiveRecord::Base) # true
|
54
|
+
event.save!
|
55
|
+
```
|
56
|
+
|
39
57
|
In order for events to actually be published, StagedEvent provides a rake task that should be kept running alongside your application server(s):
|
40
58
|
|
41
59
|
```bash
|
@@ -44,13 +62,13 @@ rake staged_event:publisher
|
|
44
62
|
|
45
63
|
### Receiving Events
|
46
64
|
|
47
|
-
|
65
|
+
To receive events from publishers, StagedEvent provides a rake task that should be kept running alongside your application server(s):
|
48
66
|
|
49
67
|
```bash
|
50
68
|
rake staged_event:subscriber
|
51
69
|
```
|
52
70
|
|
53
|
-
|
71
|
+
To specify what is done with incoming events, you define a callback in the StagedEvent initializer file.
|
54
72
|
|
55
73
|
### Regenerating Ruby from protobufs
|
56
74
|
|
data/lib/staged_event/version.rb
CHANGED
data/lib/staged_event.rb
CHANGED
@@ -49,6 +49,12 @@ module StagedEvent
|
|
49
49
|
Model.new(id: uuid, data: data, topic: topic)
|
50
50
|
end
|
51
51
|
|
52
|
+
# Shortcut method to construct and persist an event with a single call.
|
53
|
+
# Params are the same as from_proto.
|
54
|
+
def save_proto!(proto, **kwargs)
|
55
|
+
StagedEvent.from_proto(proto, **kwargs).save!
|
56
|
+
end
|
57
|
+
|
52
58
|
# Converts serialized event data received from a publisher into an object with
|
53
59
|
# the event (and its metadata) in accessible form
|
54
60
|
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: staged_event
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Cross
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
202
|
- !ruby/object:Gem::Version
|
203
203
|
version: '0'
|
204
204
|
requirements: []
|
205
|
-
rubygems_version: 3.2.
|
205
|
+
rubygems_version: 3.2.22
|
206
206
|
signing_key:
|
207
207
|
specification_version: 4
|
208
208
|
summary: StagedEvent
|