ruby_event_store-outbox 0.0.18 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_event_store/outbox/consumer.rb +4 -10
- data/lib/ruby_event_store/outbox/legacy_sidekiq_scheduler.rb +24 -0
- data/lib/ruby_event_store/outbox/metrics/test.rb +24 -0
- data/lib/ruby_event_store/outbox/repository.rb +3 -3
- data/lib/ruby_event_store/outbox/sidekiq_producer.rb +1 -1
- data/lib/ruby_event_store/outbox/sidekiq_scheduler.rb +5 -4
- data/lib/ruby_event_store/outbox/version.rb +1 -1
- data/lib/ruby_event_store/outbox.rb +1 -1
- metadata +10 -9
- data/lib/ruby_event_store/outbox/consumer_process.rb +0 -6
- data/lib/ruby_event_store/outbox/sidekiq_message_handler.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b78f20ac9a815274e65c78322746557d961af6b05982d2ebd828f65186002982
|
4
|
+
data.tar.gz: 4a88357afd1a360398d8c1b3fe1fe6081f6e5c05169ba892d16cd701dfd38b53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d82d744889b4f595ecfb9c16a6ab57817fd3d652e3c30cbe4f4367bf794de41245b82c35ae02e01e73907ae745f829b1fe3486378a8b0685eaed47d25a359fd
|
7
|
+
data.tar.gz: '058fec9678d6d6db03bc58c1e982ebce51547714dccf657ab5dd2161f2de55af0d07cd44b15e286e9186626c3cb4ad087fd100b118f235fdd7650163ca2a9f68'
|
@@ -164,24 +164,23 @@ module RubyEventStore
|
|
164
164
|
when :deadlocked
|
165
165
|
logger.warn "Obtaining lock for split_key '#{fetch_specification.split_key}' failed (deadlock)"
|
166
166
|
metrics.write_operation_result("obtain", "deadlocked")
|
167
|
-
|
167
|
+
false
|
168
168
|
when :lock_timeout
|
169
169
|
logger.warn "Obtaining lock for split_key '#{fetch_specification.split_key}' failed (lock timeout)"
|
170
170
|
metrics.write_operation_result("obtain", "lock_timeout")
|
171
|
-
|
171
|
+
false
|
172
172
|
when :taken
|
173
173
|
logger.debug "Obtaining lock for split_key '#{fetch_specification.split_key}' unsuccessful (taken)"
|
174
174
|
metrics.write_operation_result("obtain", "taken")
|
175
|
-
|
175
|
+
false
|
176
176
|
else
|
177
|
-
|
177
|
+
result
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
181
181
|
def release_lock_for_process(fetch_specification)
|
182
182
|
result = repository.release_lock_for_process(fetch_specification, consumer_uuid)
|
183
183
|
case result
|
184
|
-
when :ok
|
185
184
|
when :deadlocked
|
186
185
|
logger.warn "Releasing lock for split_key '#{fetch_specification.split_key}' failed (deadlock)"
|
187
186
|
metrics.write_operation_result("release", "deadlocked")
|
@@ -191,8 +190,6 @@ module RubyEventStore
|
|
191
190
|
when :not_taken_by_this_process
|
192
191
|
logger.debug "Releasing lock for split_key '#{fetch_specification.split_key}' failed (not taken by this process)"
|
193
192
|
metrics.write_operation_result("release", "not_taken_by_this_process")
|
194
|
-
else
|
195
|
-
raise "Unexpected result #{result}"
|
196
193
|
end
|
197
194
|
end
|
198
195
|
|
@@ -221,15 +218,12 @@ module RubyEventStore
|
|
221
218
|
def cleanup(fetch_specification)
|
222
219
|
result = cleanup_strategy.call(fetch_specification)
|
223
220
|
case result
|
224
|
-
when :ok
|
225
221
|
when :deadlocked
|
226
222
|
logger.warn "Cleanup for split_key '#{fetch_specification.split_key}' failed (deadlock)"
|
227
223
|
metrics.write_operation_result("cleanup", "deadlocked")
|
228
224
|
when :lock_timeout
|
229
225
|
logger.warn "Cleanup for split_key '#{fetch_specification.split_key}' failed (lock timeout)"
|
230
226
|
metrics.write_operation_result("cleanup", "lock_timeout")
|
231
|
-
else
|
232
|
-
raise "Unexpected result #{result}"
|
233
227
|
end
|
234
228
|
end
|
235
229
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "sidekiq_producer"
|
4
|
+
|
5
|
+
module RubyEventStore
|
6
|
+
module Outbox
|
7
|
+
class LegacySidekiqScheduler
|
8
|
+
def initialize
|
9
|
+
@sidekiq_producer = SidekiqProducer.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(klass, serialized_record)
|
13
|
+
sidekiq_producer.call(klass, [serialized_record])
|
14
|
+
end
|
15
|
+
|
16
|
+
def verify(subscriber)
|
17
|
+
Class === subscriber && subscriber.respond_to?(:through_outbox?) && subscriber.through_outbox?
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
attr_reader :sidekiq_producer
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'influxdb'
|
2
|
+
|
3
|
+
module RubyEventStore
|
4
|
+
module Outbox
|
5
|
+
module Metrics
|
6
|
+
class Test
|
7
|
+
def initialize
|
8
|
+
@operation_results = []
|
9
|
+
@queue_stats = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def write_operation_result(operation, result)
|
13
|
+
@operation_results << { operation: operation, result: result }
|
14
|
+
end
|
15
|
+
|
16
|
+
def write_point_queue(enqueued: 0, failed: 0, remaining: 0, format: nil, split_key: nil)
|
17
|
+
@queue_stats << { enqueued: enqueued, failed: failed, remaining: remaining, format: format, split_key: split_key}
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :operation_results, :queue_stats
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -36,7 +36,7 @@ module RubyEventStore
|
|
36
36
|
transaction do
|
37
37
|
l = get_lock_record(fetch_specification)
|
38
38
|
|
39
|
-
if l.recently_locked?
|
39
|
+
if l.recently_locked?(clock: clock)
|
40
40
|
:taken
|
41
41
|
else
|
42
42
|
l.update!(
|
@@ -89,8 +89,8 @@ module RubyEventStore
|
|
89
89
|
locked_by.eql?(process_uuid)
|
90
90
|
end
|
91
91
|
|
92
|
-
def recently_locked?
|
93
|
-
locked_by && locked_at > RECENTLY_LOCKED_DURATION.ago
|
92
|
+
def recently_locked?(clock:)
|
93
|
+
locked_by && locked_at > RECENTLY_LOCKED_DURATION.ago(clock.now)
|
94
94
|
end
|
95
95
|
|
96
96
|
def fetch_specification
|
@@ -10,7 +10,7 @@ module RubyEventStore
|
|
10
10
|
sidekiq_client = Sidekiq::Client.new(Sidekiq.redis_pool)
|
11
11
|
item = {
|
12
12
|
'class' => klass,
|
13
|
-
'args' => args,
|
13
|
+
'args' => args.map(&:to_h),
|
14
14
|
}
|
15
15
|
normalized_item = sidekiq_client.__send__(:normalize_item, item)
|
16
16
|
payload = sidekiq_client.__send__(:process_single, normalized_item.fetch('class'), normalized_item)
|
@@ -5,12 +5,13 @@ require_relative "sidekiq_producer"
|
|
5
5
|
module RubyEventStore
|
6
6
|
module Outbox
|
7
7
|
class SidekiqScheduler
|
8
|
-
def initialize
|
8
|
+
def initialize(serializer: YAML)
|
9
|
+
@serializer = serializer
|
9
10
|
@sidekiq_producer = SidekiqProducer.new
|
10
11
|
end
|
11
12
|
|
12
|
-
def call(klass,
|
13
|
-
sidekiq_producer.call(klass, [
|
13
|
+
def call(klass, record)
|
14
|
+
sidekiq_producer.call(klass, [record.serialize(serializer)])
|
14
15
|
end
|
15
16
|
|
16
17
|
def verify(subscriber)
|
@@ -18,7 +19,7 @@ module RubyEventStore
|
|
18
19
|
end
|
19
20
|
|
20
21
|
private
|
21
|
-
attr_reader :sidekiq_producer
|
22
|
+
attr_reader :serializer, :sidekiq_producer
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_event_store-outbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkency
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby_event_store
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '5.2'
|
41
|
-
description:
|
41
|
+
description:
|
42
42
|
email: dev@arkency.com
|
43
43
|
executables:
|
44
44
|
- res_outbox
|
@@ -55,14 +55,14 @@ files:
|
|
55
55
|
- lib/ruby_event_store/outbox/cleanup_strategies/none.rb
|
56
56
|
- lib/ruby_event_store/outbox/cli.rb
|
57
57
|
- lib/ruby_event_store/outbox/consumer.rb
|
58
|
-
- lib/ruby_event_store/outbox/consumer_process.rb
|
59
58
|
- lib/ruby_event_store/outbox/fetch_specification.rb
|
59
|
+
- lib/ruby_event_store/outbox/legacy_sidekiq_scheduler.rb
|
60
60
|
- lib/ruby_event_store/outbox/metrics.rb
|
61
61
|
- lib/ruby_event_store/outbox/metrics/influx.rb
|
62
62
|
- lib/ruby_event_store/outbox/metrics/null.rb
|
63
|
+
- lib/ruby_event_store/outbox/metrics/test.rb
|
63
64
|
- lib/ruby_event_store/outbox/repository.rb
|
64
65
|
- lib/ruby_event_store/outbox/sidekiq5_format.rb
|
65
|
-
- lib/ruby_event_store/outbox/sidekiq_message_handler.rb
|
66
66
|
- lib/ruby_event_store/outbox/sidekiq_processor.rb
|
67
67
|
- lib/ruby_event_store/outbox/sidekiq_producer.rb
|
68
68
|
- lib/ruby_event_store/outbox/sidekiq_scheduler.rb
|
@@ -74,7 +74,8 @@ metadata:
|
|
74
74
|
homepage_uri: https://railseventstore.org
|
75
75
|
source_code_uri: https://github.com/RailsEventStore/rails_event_store
|
76
76
|
bug_tracker_uri: https://github.com/RailsEventStore/rails_event_store/issues
|
77
|
-
|
77
|
+
rubygems_mfa_required: 'true'
|
78
|
+
post_install_message:
|
78
79
|
rdoc_options: []
|
79
80
|
require_paths:
|
80
81
|
- lib
|
@@ -89,8 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
90
|
- !ruby/object:Gem::Version
|
90
91
|
version: '0'
|
91
92
|
requirements: []
|
92
|
-
rubygems_version: 3.
|
93
|
-
signing_key:
|
93
|
+
rubygems_version: 3.2.22
|
94
|
+
signing_key:
|
94
95
|
specification_version: 4
|
95
96
|
summary: Active Record based outbox for Ruby Event Store
|
96
97
|
test_files: []
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require "sidekiq"
|
2
|
-
|
3
|
-
module RubyEventStore
|
4
|
-
module Outbox
|
5
|
-
class SidekiqMessageHandler
|
6
|
-
def initialize
|
7
|
-
@sidekiq = Sidekiq::Client.new(Sidekiq.redis_pool)
|
8
|
-
end
|
9
|
-
|
10
|
-
def init
|
11
|
-
end
|
12
|
-
|
13
|
-
def handle_one_record(now, record)
|
14
|
-
hash_payload = JSON.parse(record.payload)
|
15
|
-
@sidekiq.__send__(:raw_push, [hash_payload])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|