active_event_store 1.3.0 → 1.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/CHANGELOG.md +7 -0
- data/README.md +10 -0
- data/lib/active_event_store/config.rb +1 -1
- data/lib/active_event_store/engine.rb +21 -2
- data/lib/active_event_store/version.rb +1 -1
- data/lib/active_event_store.rb +31 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a05deabdbcd4baa4ec3a0e6e0ef4696b7913af826913ab0b8ce1ef45e97886dd
|
|
4
|
+
data.tar.gz: 12c2eafe4f93d63188344e341c01060bbcdbbb1e83328df7689b35c99346502d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7eb6392317c966efae31a8eea8ad935e178af3ea0a61c036fded170d32b39c2d1758b0853ba6df75f6c4b898ee24866400a385c5d04aae3ff99268d8f7c8dbf4
|
|
7
|
+
data.tar.gz: 48bda0e29b746d8dfe3b265df265eb398e55a61b6a414ed4980a5887822fa5fd3c7b332cf2b0c55fc666d28824bbf1b58e717959b4c0c65f00dc516838cd36d4
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## master
|
|
4
4
|
|
|
5
|
+
## 1.4.0 (2026-07-17)
|
|
6
|
+
|
|
7
|
+
- Support `wait:` / `wait_until:` on asynchronous `subscribe`, scheduling the subscriber job to run after a delay. ([@rickychilcott][])
|
|
8
|
+
|
|
9
|
+
- Support rails_event_store 3.0 by using the renamed `RailsEventStore::AfterCommitDispatcher`, `RubyEventStore::SyncScheduler` and `RubyEventStore::ActiveRecord::EventRepository`, falling back to the pre-2.19 names when running on older versions. ([#24](https://github.com/palkan/active_event_store/issues/24))
|
|
10
|
+
|
|
5
11
|
## 1.3.0 (2025-12-04)
|
|
6
12
|
|
|
7
13
|
- Update Rails Event Store configuration to avoid deprecation warning ([@christophermlne][], [@phil-monroe][])
|
|
@@ -51,3 +57,4 @@ Now `ActiveSupport.on_load(:active_event_store) { ... }` works.
|
|
|
51
57
|
[@chriscz]: https://github.com/chriscz
|
|
52
58
|
[@caws]: https://github.com/caws
|
|
53
59
|
[@Samsinite]: https://github.com/Samsinite
|
|
60
|
+
[@rickychilcott]: https://github.com/rickychilcott
|
data/README.md
CHANGED
|
@@ -128,6 +128,16 @@ ActiveSupport.on_load :active_event_store do |store|
|
|
|
128
128
|
# sync subscriber – invoked right "within" `publish` method
|
|
129
129
|
store.subscribe MyEventHandler, to: ProfileCreated, sync: true
|
|
130
130
|
|
|
131
|
+
# delayed async subscriber – the background job is enqueued with a delay.
|
|
132
|
+
# `wait:` and `wait_until:` are passed through to Active Job's `.set`.
|
|
133
|
+
# `wait:` (a duration or number of seconds) is applied relative to when the
|
|
134
|
+
# event is published, so this reads "10 minutes after the event".
|
|
135
|
+
store.subscribe MyEventHandler, to: ProfileCreated, wait: 10.minutes
|
|
136
|
+
|
|
137
|
+
# NOTE: `wait_until:` is an absolute time, captured when `subscribe` runs
|
|
138
|
+
# (i.e. at boot). Prefer `wait:` unless you truly mean a fixed moment.
|
|
139
|
+
store.subscribe MyEventHandler, to: ProfileCreated, wait_until: Date.parse("2030-01-01").midnight
|
|
140
|
+
|
|
131
141
|
# anonymous handler (could only be synchronous)
|
|
132
142
|
store.subscribe(to: ProfileCreated, sync: true) do |event|
|
|
133
143
|
# do something
|
|
@@ -7,7 +7,7 @@ module ActiveEventStore
|
|
|
7
7
|
attr_writer :repository, :serializer, :job_queue_name, :store_options
|
|
8
8
|
|
|
9
9
|
def repository
|
|
10
|
-
@repository ||=
|
|
10
|
+
@repository ||= RubyEventStore::ActiveRecord::EventRepository.new(serializer: serializer)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def serializer
|
|
@@ -15,16 +15,35 @@ module ActiveEventStore
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
config.to_prepare do
|
|
18
|
+
# `AfterCommitAsyncDispatcher` was renamed to `AfterCommitDispatcher` in
|
|
19
|
+
# rails_event_store 2.19.0 and removed in 3.0.0. Both share the same
|
|
20
|
+
# `scheduler:` interface, so pick whichever is available.
|
|
21
|
+
after_commit_dispatcher_class =
|
|
22
|
+
if defined?(RailsEventStore::AfterCommitDispatcher)
|
|
23
|
+
RailsEventStore::AfterCommitDispatcher
|
|
24
|
+
else
|
|
25
|
+
RailsEventStore::AfterCommitAsyncDispatcher
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# `RubyEventStore::Dispatcher` was renamed to `SyncScheduler` in the same
|
|
29
|
+
# release (2.19.0) and removed in 3.0.0.
|
|
30
|
+
sync_dispatcher =
|
|
31
|
+
if defined?(RubyEventStore::SyncScheduler)
|
|
32
|
+
RubyEventStore::SyncScheduler.new
|
|
33
|
+
else
|
|
34
|
+
RubyEventStore::Dispatcher.new
|
|
35
|
+
end
|
|
36
|
+
|
|
18
37
|
# See https://railseventstore.org/docs/subscribe/#scheduling-async-handlers-after-commit
|
|
19
38
|
ActiveEventStore.event_store = RailsEventStore::Client.new(
|
|
20
39
|
message_broker: RubyEventStore::Broker.new(
|
|
21
40
|
dispatcher: RubyEventStore::ComposedDispatcher.new(
|
|
22
|
-
|
|
41
|
+
after_commit_dispatcher_class.new(
|
|
23
42
|
scheduler: RailsEventStore::ActiveJobScheduler.new(
|
|
24
43
|
serializer: ActiveEventStore.config.serializer
|
|
25
44
|
)
|
|
26
45
|
),
|
|
27
|
-
|
|
46
|
+
sync_dispatcher
|
|
28
47
|
)
|
|
29
48
|
),
|
|
30
49
|
repository: ActiveEventStore.config.repository,
|
data/lib/active_event_store.rb
CHANGED
|
@@ -25,7 +25,7 @@ module ActiveEventStore
|
|
|
25
25
|
@config ||= Config.new
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
def subscribe(subscriber = nil, to: nil, sync: false, &block)
|
|
28
|
+
def subscribe(subscriber = nil, to: nil, sync: false, wait: nil, wait_until: nil, &block)
|
|
29
29
|
subscriber ||= block
|
|
30
30
|
|
|
31
31
|
to ||= infer_event_from_subscriber(subscriber) if subscriber.is_a?(Module)
|
|
@@ -35,6 +35,8 @@ module ActiveEventStore
|
|
|
35
35
|
"Please, specify event using `to:` option"
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
+
assert_valid_enqueue_options!(sync: sync, wait: wait, wait_until: wait_until)
|
|
39
|
+
|
|
38
40
|
identifier =
|
|
39
41
|
if to.is_a?(Class) && to <= ActiveEventStore::Event
|
|
40
42
|
# register event
|
|
@@ -45,7 +47,15 @@ module ActiveEventStore
|
|
|
45
47
|
to
|
|
46
48
|
end
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
unless sync
|
|
51
|
+
subscriber = SubscriberJob.from(subscriber)
|
|
52
|
+
|
|
53
|
+
# Defer the subscriber job by passing Active Job's own scheduling options
|
|
54
|
+
# through `.set`. The resulting ConfiguredJob is dispatched via
|
|
55
|
+
# `perform_later`, so the delay is applied when the event is published.
|
|
56
|
+
enqueue_options = {wait: wait, wait_until: wait_until}.compact
|
|
57
|
+
subscriber = subscriber.set(**enqueue_options) unless enqueue_options.empty?
|
|
58
|
+
end
|
|
49
59
|
|
|
50
60
|
event_store.subscribe subscriber, to: [identifier]
|
|
51
61
|
end
|
|
@@ -56,6 +66,25 @@ module ActiveEventStore
|
|
|
56
66
|
|
|
57
67
|
private
|
|
58
68
|
|
|
69
|
+
# `wait:`/`wait_until:` are forwarded to Active Job's `.set` verbatim, and it
|
|
70
|
+
# does not evaluate callables — validate here so a bad value fails at the
|
|
71
|
+
# subscription site instead of deep inside job dispatch, long after this ran.
|
|
72
|
+
def assert_valid_enqueue_options!(sync:, wait:, wait_until:)
|
|
73
|
+
return unless wait || wait_until
|
|
74
|
+
|
|
75
|
+
if sync
|
|
76
|
+
raise ArgumentError, "`wait:`/`wait_until:` are only supported for async subscribers"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
if wait && !(wait.is_a?(Numeric) || wait.is_a?(ActiveSupport::Duration))
|
|
80
|
+
raise ArgumentError, "`wait:` must be a number of seconds or an ActiveSupport::Duration (e.g. `10.minutes`), got #{wait.class}"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
if wait_until && !wait_until.acts_like?(:time)
|
|
84
|
+
raise ArgumentError, "`wait_until:` must be a time (e.g. `1.hour.from_now`), got #{wait_until.class}"
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
59
88
|
def infer_event_from_subscriber(subscriber)
|
|
60
89
|
event_class_name = subscriber.name.split("::").yield_self do |parts|
|
|
61
90
|
# handle explicti top-level name, e.g. ::Some::Event
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_event_store
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vladimir Dementyev
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-07-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails_event_store
|