event_engine-subscribers 0.3.0 → 0.4.0
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 +8 -10
- data/lib/event_engine/subscribers/engine.rb +10 -0
- data/lib/event_engine/subscribers/version.rb +1 -1
- data/lib/event_engine/subscribers.rb +5 -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: 9911cefcbfa87b20178f615e68e88cef8f57da763ad42fcdf10a3f7f1b9d7be9
|
|
4
|
+
data.tar.gz: 1aa83bfbbea17ba4b3d2555f08509545f487e94d38abc52409de1a97bfa52109
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 64e5c8652616821523641c4ffa5e17afb165e052847cde405c42f9ba2e852ed90a5c77add76ba3d6315e4fe230b97c280ff6213db5671c18a94e41757d957f82
|
|
7
|
+
data.tar.gz: 6b420c78274b70abf4cda7d544074e692e400409dac035937204b2270a0a2605b9a3f63198d46b0c9201c49cd3406aab5a6d1f789de28defe4c69aaf4f6fd88c
|
data/README.md
CHANGED
|
@@ -104,23 +104,21 @@ The check runs once the app has started, after every class in `app/subscribers`
|
|
|
104
104
|
registered. A subscriber anywhere else registers only once Rails has loaded its class,
|
|
105
105
|
so keep subscribers in `app/subscribers`.
|
|
106
106
|
|
|
107
|
-
## Requiring
|
|
107
|
+
## Requiring a pack's events to run inline
|
|
108
108
|
|
|
109
109
|
A subscriber that refuses a change can only undo it when it runs inline, during the
|
|
110
|
-
emit. A host that depends on that
|
|
111
|
-
processors are registered:
|
|
110
|
+
emit. A host that depends on that names the event packs whose events must run inline:
|
|
112
111
|
|
|
113
112
|
```ruby
|
|
114
113
|
# config/application.rb
|
|
115
|
-
config.
|
|
116
|
-
EventEngine::Subscribers.check_inline!(EventEngine::Subscribers.routes)
|
|
117
|
-
end
|
|
114
|
+
config.event_engine_subscribers.inline_packs = [:console]
|
|
118
115
|
```
|
|
119
116
|
|
|
120
|
-
|
|
121
|
-
nothing registered, or when
|
|
122
|
-
|
|
123
|
-
|
|
117
|
+
When the app starts, the gem then refuses to start when an event has no rule, when a
|
|
118
|
+
rule names a processor nothing registered, or when an event in a named pack is routed to
|
|
119
|
+
`background`. The last error names every such event. Events in other packs may still
|
|
120
|
+
run in the background. With no packs named, which is the default, the gem runs no inline
|
|
121
|
+
check.
|
|
124
122
|
|
|
125
123
|
## A working example app
|
|
126
124
|
|
|
@@ -5,6 +5,9 @@ module EventEngine
|
|
|
5
5
|
class Engine < ::Rails::Engine
|
|
6
6
|
isolate_namespace EventEngine::Subscribers
|
|
7
7
|
|
|
8
|
+
config.event_engine_subscribers = ActiveSupport::OrderedOptions.new
|
|
9
|
+
config.event_engine_subscribers.inline_packs = []
|
|
10
|
+
|
|
8
11
|
initializer "event_engine.subscribers.register_processor" do
|
|
9
12
|
config.after_initialize do
|
|
10
13
|
processor = Processor.new
|
|
@@ -18,6 +21,13 @@ module EventEngine
|
|
|
18
21
|
config.after_initialize { Subscribers.check!(Subscribers.routes) }
|
|
19
22
|
end
|
|
20
23
|
|
|
24
|
+
initializer "event_engine.subscribers.check_inline_packs", after: "event_engine.subscribers.register_processor" do |app|
|
|
25
|
+
config.after_initialize do
|
|
26
|
+
packs = app.config.event_engine_subscribers.inline_packs
|
|
27
|
+
Subscribers.check_inline!(Subscribers.routes, packs: packs) if packs.any?
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
21
31
|
initializer "event_engine.subscribers.forget_unloaded_subscribers" do |app|
|
|
22
32
|
app.reloader.before_class_unload { Registry.clear! }
|
|
23
33
|
end
|
|
@@ -25,12 +25,16 @@ module EventEngine
|
|
|
25
25
|
true
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
def self.check_inline!(routes)
|
|
28
|
+
def self.check_inline!(routes, packs: nil)
|
|
29
29
|
EventEngine.validate_rules!
|
|
30
30
|
background = routes.reject { |_event_name, process_type| process_type == :inline }.keys
|
|
31
|
+
background = background.select { |event_name| packs.include?(pack_of(event_name)) } if packs
|
|
31
32
|
raise BackgroundEventsError, background if background.any?
|
|
32
33
|
|
|
33
34
|
true
|
|
34
35
|
end
|
|
36
|
+
|
|
37
|
+
def self.pack_of(event_name) = EventEngine.schema_registry.latest_for(event_name).domain
|
|
38
|
+
private_class_method :pack_of
|
|
35
39
|
end
|
|
36
40
|
end
|