staged_event 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 626ddab89e43654e2f9f7444efbbb778e40a02882142e5bab971a253d0586278
4
- data.tar.gz: 77bf67900459f69099d58913d8ae49140c934d49239f1ebf043e0924d127632e
3
+ metadata.gz: e9857444ea3c1fe90c3384ebb2c0885b1238c318ee004ea15bbc8416e2956ee2
4
+ data.tar.gz: 130bb8f5daea2d867ab302878c90b9b1051666728ac61df082c39f4fb8337be1
5
5
  SHA512:
6
- metadata.gz: 19f8edb5ba417a59bae2d5e62f68437d34a1563b3996fe2d848c6515292136970f071ef7ed75bbc6e9bdac7404a317b5330ba8d1cd3a4bfca40ca0160ea7ba1b
7
- data.tar.gz: 7dc404d84752a7aeeda6897cbb47dda3168d86219e3fdc809e21b5dac230a829d2b266fb361f51ac21d0acf0b5ab3bd566a5121181b4853644b4b272a1f55f4e
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
- In order to receive events from publishers, StagedEvent provides a rake task that should be kept running alongside your application server(s):
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
- In order to process incoming events, you define a callback in the staged_event initializer file.
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
 
@@ -15,6 +15,8 @@ StagedEvent::Configuration.configure do |config|
15
15
  default: "topic_id_1",
16
16
  }
17
17
 
18
+ # The list of subscription ids to which the staged_event subscriber process will
19
+ # subscribe.
18
20
  google_pubsub.subscription_ids = [ "subscription_id_1" ]
19
21
  end
20
22
 
@@ -18,6 +18,8 @@ module StagedEvent
18
18
  error :publish_failed, exception: exception.message
19
19
  backoff_timer.increment
20
20
  retry
21
+ rescue SignalException => exception
22
+ error :signal_exception, message: exception.message
21
23
  end
22
24
 
23
25
  private
@@ -13,6 +13,8 @@ module StagedEvent
13
13
  rescue StandardError => exception
14
14
  error :subscriber_main_loop_failed, exception: exception.message
15
15
  retry
16
+ rescue SignalException => exception
17
+ error :signal_exception, message: exception.message
16
18
  end
17
19
 
18
20
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StagedEvent
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
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.1
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: 2021-10-12 00:00:00.000000000 Z
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.15
205
+ rubygems_version: 3.2.22
206
206
  signing_key:
207
207
  specification_version: 4
208
208
  summary: StagedEvent